Skip to content

Commit 3214349

Browse files
signing in with google provider
1 parent e922d74 commit 3214349

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SwiftUI
33

44
public protocol GoogleProviderProtocol {
55
func handleUrl(_ url: URL) -> Bool
6-
func signInWithGoogle(clientID: String)
6+
@MainActor func signInWithGoogle(clientID: String) async throws -> AuthCredential
77
}
88

99
public enum AuthenticationProvider {
@@ -111,7 +111,9 @@ public final class AuthService {
111111
NSLocalizedDescriptionKey: "OAuth client ID not found. Please make sure Google Sign-In is enabled in the Firebase console. You may have to download a new GoogleService-Info.plist file after enabling Google Sign-In.",
112112
]
113113
) }
114-
try safeGoogleProvider.signInWithGoogle(clientID: clientID)
114+
let credential = try await safeGoogleProvider.signInWithGoogle(clientID: clientID)
115+
116+
try await signIn(with: credential)
115117
updateAuthenticationState()
116118
} catch {
117119
authenticationState = .unauthenticated

FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Services/GoogleProviderSwift.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public class GoogleProviderSwift: @preconcurrency GoogleProviderProtocol {
1313
public init(scopes: [String]? = nil) {
1414
self.scopes = scopes ?? kDefaultScopes
1515
}
16-
16+
1717
public func handleUrl(_ url: URL) -> Bool {
1818
return GIDSignIn.sharedInstance.handle(url)
1919
}
20-
20+
2121
@MainActor public func signInWithGoogle(clientID: String) async throws -> AuthCredential {
22-
guard let presentingViewController = (UIApplication.shared.connectedScenes
22+
guard let presentingViewController = await (UIApplication.shared.connectedScenes
2323
.first as? UIWindowScene)?.windows.first?.rootViewController else {
2424
throw NSError(
2525
domain: "GoogleProviderSwiftErrorDomain",
@@ -29,10 +29,10 @@ public class GoogleProviderSwift: @preconcurrency GoogleProviderProtocol {
2929
]
3030
)
3131
}
32-
32+
3333
let config = GIDConfiguration(clientID: clientID)
3434
GIDSignIn.sharedInstance.configuration = config
35-
35+
3636
return try await withCheckedThrowingContinuation { continuation in
3737
GIDSignIn.sharedInstance.signIn(
3838
withPresenting: presentingViewController
@@ -41,7 +41,7 @@ public class GoogleProviderSwift: @preconcurrency GoogleProviderProtocol {
4141
continuation.resume(throwing: error)
4242
return
4343
}
44-
44+
4545
guard let user = result?.user,
4646
let idToken = user.idToken?.tokenString else {
4747
continuation.resume(throwing: NSError(
@@ -53,7 +53,7 @@ public class GoogleProviderSwift: @preconcurrency GoogleProviderProtocol {
5353
))
5454
return
5555
}
56-
56+
5757
let credential = GoogleAuthProvider.credential(withIDToken: idToken,
5858
accessToken: user.accessToken.tokenString)
5959
continuation.resume(returning: credential)

0 commit comments

Comments
 (0)