diff --git a/Splito/UI/Home/Account/User Profile/UserProfileViewModel.swift b/Splito/UI/Home/Account/User Profile/UserProfileViewModel.swift index 523d97eb8..258d4c429 100644 --- a/Splito/UI/Home/Account/User Profile/UserProfileViewModel.swift +++ b/Splito/UI/Home/Account/User Profile/UserProfileViewModel.swift @@ -264,12 +264,12 @@ extension UserProfileViewModel { request.requestedScopes = [.fullName, .email] request.nonce = NonceGenerator.sha256(currentNonce) - isDeleteInProgress = false - appleSignInDelegates = SignInWithAppleDelegates { (token, _, _, _) in - self.isDeleteInProgress = true - let credential = OAuthProvider.credential(providerID: AuthProviderID(rawValue: "apple.com")!, idToken: token, rawNonce: self.currentNonce) + let credential = OAuthProvider.credential(providerID: AuthProviderID.apple, + idToken: token, rawNonce: self.currentNonce) completion(credential) + } onError: { + self.isDeleteInProgress = false } let authorizationController = ASAuthorizationController(authorizationRequests: [request]) @@ -278,7 +278,10 @@ extension UserProfileViewModel { } private func handleGoogleLogin(completion: @escaping (AuthCredential?) -> Void) { - let clientID = FirebaseApp.app()?.options.clientID ?? "" + guard let clientID = FirebaseApp.app()?.options.clientID else { + isDeleteInProgress = false + return + } let config = GIDConfiguration(clientID: clientID) GIDSignIn.sharedInstance.configuration = config @@ -296,7 +299,10 @@ extension UserProfileViewModel { return } - guard let user = result?.user, let idToken = user.idToken?.tokenString else { return } + guard let user = result?.user, let idToken = user.idToken?.tokenString else { + self.isDeleteInProgress = false + return + } let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: user.accessToken.tokenString) completion(credential) } diff --git a/Splito/UI/Login/LoginViewModel.swift b/Splito/UI/Login/LoginViewModel.swift index bc524103a..5ae7e9931 100644 --- a/Splito/UI/Login/LoginViewModel.swift +++ b/Splito/UI/Login/LoginViewModel.swift @@ -82,6 +82,8 @@ public class LoginViewModel: BaseViewModel, ObservableObject { idToken: token, rawNonce: self.currentNonce) self.performFirebaseLogin(showAppleLoading: self.showAppleLoading, credential: credential, loginType: .Apple, userData: (fName, lName, email)) + } onError: { + self.showAppleLoading = false } let authorizationController = ASAuthorizationController(authorizationRequests: [request]) diff --git a/Splito/UI/Login/SignInWithAppleDelegate.swift b/Splito/UI/Login/SignInWithAppleDelegate.swift index 21b4d1c0d..426722a40 100644 --- a/Splito/UI/Login/SignInWithAppleDelegate.swift +++ b/Splito/UI/Login/SignInWithAppleDelegate.swift @@ -11,9 +11,11 @@ import AuthenticationServices class SignInWithAppleDelegates: NSObject { private let signInSucceeded: (String, String, String, String) -> Void + private let onError: (() -> Void) - init(signInSucceeded: @escaping (String, String, String, String) -> Void) { + init(signInSucceeded: @escaping (String, String, String, String) -> Void, onError: @escaping () -> Void) { self.signInSucceeded = signInSucceeded + self.onError = onError } } @@ -23,11 +25,13 @@ extension SignInWithAppleDelegates: ASAuthorizationControllerDelegate { guard let appleIDToken = appleIDCredential.identityToken else { LogE("SignInWithAppleDelegates: \(#function) Unable to fetch identity token.") + onError() return } guard let idTokenString = String(data: appleIDToken, encoding: .utf8) else { LogE("SignInWithAppleDelegates: \(#function) Unable to serialize token string from data: \(appleIDToken.debugDescription).") + onError() return } @@ -41,5 +45,6 @@ extension SignInWithAppleDelegates: ASAuthorizationControllerDelegate { func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) { LogE("SignInWithAppleDelegates: \(#function) Apple login complete with error: \(error).") + onError() } }