diff --git a/Data/Data/Model/AppUser.swift b/Data/Data/Model/AppUser.swift index 87f3dd80c..dc265aac6 100644 --- a/Data/Data/Model/AppUser.swift +++ b/Data/Data/Model/AppUser.swift @@ -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 { diff --git a/Data/Data/Repository/UserRepository.swift b/Data/Data/Repository/UserRepository.swift index 5121fad13..d4c6a8628 100644 --- a/Data/Data/Repository/UserRepository.swift +++ b/Data/Data/Repository/UserRepository.swift @@ -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 }