Skip to content

Commit

Permalink
Fix: getting loader after dismiss apple login sheet in between
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-nirali-s committed Dec 17, 2024
1 parent 430dc21 commit d27ac8e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
18 changes: 12 additions & 6 deletions Splito/UI/Home/Account/User Profile/UserProfileViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
Expand All @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions Splito/UI/Login/LoginViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
7 changes: 6 additions & 1 deletion Splito/UI/Login/SignInWithAppleDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
}

Expand All @@ -41,5 +45,6 @@ extension SignInWithAppleDelegates: ASAuthorizationControllerDelegate {

func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
LogE("SignInWithAppleDelegates: \(#function) Apple login complete with error: \(error).")
onError()
}
}

0 comments on commit d27ac8e

Please sign in to comment.