Skip to content

Commit

Permalink
fix when user logs in again after delete account, remains deactivated
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-nirali-s committed Dec 9, 2024
1 parent 4bc6cd7 commit ad51a5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Data/Data/Model/AppUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct AppUser: Identifiable, Codable, Hashable {
public var deviceFcmToken: String?
public let loginType: LoginType
public var totalOweAmount: Double
public let isActive: Bool
public var isActive: Bool

public var fullName: String {
if let firstName, let lastName {
Expand Down
12 changes: 8 additions & 4 deletions Data/Data/Repository/UserRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ public class UserRepository: ObservableObject {
@Inject private var storageManager: StorageManager

public func storeUser(user: AppUser) async throws -> AppUser {
if let storedUser = try await store.fetchUserBy(id: user.id) {
LogD("UserRepository: \(#function) User already exists in Firestore: \(storedUser)")
return storedUser
if var fetchedUser = try await store.fetchUserBy(id: user.id) {
LogD("UserRepository: \(#function) User already exists in Firestore.")
if !fetchedUser.isActive {
fetchedUser.isActive = true
return try await updateUser(user: fetchedUser)
}
return fetchedUser
} else {
LogD("UserRepository: \(#function) User does not exist. Adding new user: \(user)")
LogD("UserRepository: \(#function) User does not exist. Adding new user.")
try await store.addUser(user: user)
return user
}
Expand Down

0 comments on commit ad51a5a

Please sign in to comment.