File tree Expand file tree Collapse file tree
FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Services Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ @preconcurrency import FirebaseAuth
12import FirebaseAuthSwiftUI
23import GoogleSignIn
34
@@ -16,4 +17,35 @@ public class GoogleProviderSwift: GoogleProviderProtocol {
1617 public func handleUrl( _ url: URL ) -> Bool {
1718 return GIDSignIn . sharedInstance. handle ( url)
1819 }
20+
21+ @MainActor public func signInWithGoogle( clientID: String ) {
22+ guard let presentingViewController = ( UIApplication . shared. connectedScenes
23+ . first as? UIWindowScene ) ? . windows. first? . rootViewController else {
24+ // "Error: Unable to get the presenting view controller."
25+ return
26+ }
27+
28+ let config = GIDConfiguration ( clientID: clientID)
29+ GIDSignIn . sharedInstance. configuration = config
30+
31+ GIDSignIn . sharedInstance. signIn (
32+ withPresenting: presentingViewController
33+ ) { result, error in
34+ guard error == nil else {
35+ // Handle error
36+ return
37+ }
38+
39+ guard let user = result? . user,
40+ let idToken = user. idToken? . tokenString else {
41+ // Handle error
42+ return
43+ }
44+
45+ let credential = GoogleAuthProvider . credential ( withIDToken: idToken,
46+ accessToken: user. accessToken
47+ . tokenString)
48+
49+ }
50+ }
1951}
You can’t perform that action at this time.
0 commit comments