Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
borut-t committed Aug 9, 2024
1 parent cb1cfb4 commit 51b7f72
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions Sources/Google/GoogleAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 51b7f72

Please sign in to comment.