diff --git a/Sources/Google/GoogleAuthenticator.swift b/Sources/Google/GoogleAuthenticator.swift index 6e7f88d..539b986 100644 --- a/Sources/Google/GoogleAuthenticator.swift +++ b/Sources/Google/GoogleAuthenticator.swift @@ -23,14 +23,20 @@ extension GoogleAuthenticator: Authenticator { /// SignIn user. /// /// Will asynchronously return the `Response` object on success or `Error` on error. - public func signIn(from presentingViewController: UIViewController, - hint: String? = .none, - additionalScopes: [String]? = .none) async throws -> Response { + public func signIn( + from presentingViewController: UIViewController, + hint: String? = .none, + additionalScopes: [String]? = .none + ) async throws -> Response { guard !provider.hasPreviousSignIn() else { return try await restorePreviousSignIn() } - return try await signInUser(from: presentingViewController, hint: hint, additionalScopes: additionalScopes) + return try await signInUser( + from: presentingViewController, + hint: hint, + additionalScopes: additionalScopes + ) } /// Clears the signIn footprint and logs out the user immediatelly. @@ -46,7 +52,11 @@ extension GoogleAuthenticator: Authenticator { /// Boolean if given `url` should be handled. /// /// Call this from UIApplicationDelegate’s `application:openURL:options:` method. - public func canOpenUrl(_ url: URL, application: UIApplication, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool { + public func canOpenUrl( + _ url: URL, + application: UIApplication, + options: [UIApplication.OpenURLOptionsKey : Any] + ) -> Bool { GIDSignIn.sharedInstance.handle(url) } } @@ -70,11 +80,15 @@ private extension GoogleAuthenticator { func signInUser(from presentingViewController: UIViewController, hint: String?, additionalScopes: [String]?) async throws -> Response { try await withCheckedThrowingContinuation { continuation in provider - .signIn(withPresenting: presentingViewController, hint: hint, additionalScopes: additionalScopes) { result, error in + .signIn( + withPresenting: presentingViewController, + hint: hint, + additionalScopes: additionalScopes + ) { result, error in switch (result, error) { case (let signInResult?, _): continuation.resume(returning: signInResult.user.authResponse) - case (_, let actualError?): + case (let result, let actualError?): let errorCode = (actualError as NSError).code if errorCode == GIDSignInError.Code.canceled.rawValue { continuation.resume(throwing: Error.cancelled)