Skip to content

Commit fb7d515

Browse files
sign in with google init
1 parent c580003 commit fb7d515

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Services/FirebaseGoogleSwiftUI.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@preconcurrency import FirebaseAuth
12
import FirebaseAuthSwiftUI
23
import 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
}

0 commit comments

Comments
 (0)