diff --git a/Modules/AccountKit/Sources/Authentication/AuthManager.swift b/Modules/AccountKit/Sources/Authentication/AuthManager.swift index 7c36abdf1..87db8b983 100644 --- a/Modules/AccountKit/Sources/Authentication/AuthManager.swift +++ b/Modules/AccountKit/Sources/Authentication/AuthManager.swift @@ -56,6 +56,7 @@ public class AuthManager { } else if let user = authResult?.user { log.info("User \(user.uid) signed-in successfully. 🎉") self?.authenticationState.send(.loggedIn) + self?.emailVerificationState.send(user.isEmailVerified) } } } @@ -94,16 +95,24 @@ public class AuthManager { self.authenticationError.eraseToAnyPublisher() } + var emailVerificationStatePublisher: AnyPublisher { + self.emailVerificationState.eraseToAnyPublisher() + } + // MARK: Private private let authenticationState = CurrentValueSubject(.unknown) private let authenticationError = PassthroughSubject() + private let emailVerificationState = PassthroughSubject() private let auth = Auth.auth() private var cancellables = Set() private func updateAuthState(for user: User?) { - // TODO(@macteuts): Check email verification Status when relevant - let newState = user != nil ? AuthenticationState.loggedIn : .loggedOut - self.authenticationState.send(newState) + guard let user else { + self.authenticationState.send(.loggedOut) + return + } + self.authenticationState.send(.loggedIn) + self.emailVerificationState.send(user.isEmailVerified) } } diff --git a/Modules/AccountKit/Sources/Authentication/AuthManagerViewModel.swift b/Modules/AccountKit/Sources/Authentication/AuthManagerViewModel.swift index e51152f5c..1f69cac78 100644 --- a/Modules/AccountKit/Sources/Authentication/AuthManagerViewModel.swift +++ b/Modules/AccountKit/Sources/Authentication/AuthManagerViewModel.swift @@ -19,11 +19,14 @@ public class AuthManagerViewModel: ObservableObject { @Published public var userAuthenticationState: AuthManager.AuthenticationState = .unknown @Published public var userIsSigningUp = false + @Published public var userEmailIsVerified = false // MARK: - Alerts @Published public var errorMessage: String = "" @Published public var showErrorAlert = false + @Published public var actionRequestMessage: String = "" + @Published public var showactionRequestAlert = false @Published public var notificationMessage: String = "" @Published public var showNotificationAlert = false @@ -52,6 +55,13 @@ public class AuthManagerViewModel: ObservableObject { self?.showErrorAlert = true } .store(in: &self.cancellables) + + self.authManager.emailVerificationStatePublisher + .receive(on: DispatchQueue.main) + .sink { [weak self] state in + self?.userEmailIsVerified = state + } + .store(in: &self.cancellables) } private func handleAuthenticationStateChange(state: AuthManager.AuthenticationState) { @@ -60,11 +70,11 @@ public class AuthManagerViewModel: ObservableObject { if self.userIsSigningUp { self.notificationMessage = String(l10n.AuthManagerViewModel.successfulEmailVerification.characters) self.showNotificationAlert = true - } else { - // Handle unverified Sign-in + } else if !self.userEmailIsVerified { + self.actionRequestMessage = "Your email hasn't been verified yet. Please verify your email to avoid losing your data." + self.showactionRequestAlert = true } case .loggedOut: - log.info("User signed-out successfuly.") self.resetState() case .unknown: break