I don’t know the place to go from right here and am struggling to know my choices.
Following documentation right here I’m utilizing swiftUI and never swift they’ve:
guard let clientID = FirebaseApp.app()?.choices.clientID else { return }
// Create Google Signal In configuration object.
let config = GIDConfiguration(clientID: clientID)
GIDSignIn.sharedInstance.configuration = config
// Begin the check in stream!
GIDSignIn.sharedInstance.signIn(withPresenting: self) { [unowned self] outcome, error in
guard error == nil else {
// ...
}
guard let person = outcome?.person,
let idToken = person.idToken?.tokenString
else {
// ...
}
let credential = GoogleAuthProvider.credential(withIDToken: idToken,
accessToken: person.accessToken.tokenString)
// ...
}
That is my code:
func googleSignIn() {
// Configure Google Signal-In
guard let clientID = FirebaseApp.app()?.choices.clientID else {
print("Didn't get clientID")
return
}
// Create a configuration with the mandatory scopes
let configuration = GIDConfiguration(clientID: clientID)
// Register with Google
GIDSignIn.sharedInstance.signIn(
with: configuration,
presenting: getRootViewController())
{ outcome, error in
if let error = error {
print("Error signing in: (error.localizedDescription)")
return
}
guard let outcome = outcome else {
print("No outcome discovered")
return
}
// Profitable sign-in, retrieve ID token and entry token
guard let idToken = outcome.person.idToken?.tokenString,
let accessToken = outcome.person.accessToken?.tokenString else {
print("Didn't retrieve tokens")
return
}
// Create a Firebase credential with the Google tokens
let credential = Firebase.GoogleAuthProvider.credential(withIDToken: idToken, accessToken: accessToken)
// Register to Firebase with the Google credential
Firebase.Auth.auth().signIn(with: credential) { authResult, error in
if let error = error {
print("Firebase sign-in error: (error.localizedDescription)")
return
}
// Replace the isLoggedIn state
DispatchQueue.important.async {
self.isLoggedIn = true
}
print("Firebase sign-in profitable")
}
}
}
// Perform to get the basis view controller for presenting the sign-in display
func getRootViewController() -> UIViewController {
guard let rootVC = UIApplication.shared.connectedScenes
.compactMap({ $0 as? UIWindowScene })
.first?.home windows
.first(the place: { $0.isKeyWindow })?.rootViewController else {
fatalError("Root view controller not set")
}
return rootVC
}
Nonetheless I’m not capable of even construct the app due to the error involving an ‘additional trailing closure in name’ however I’m actually simply following the documentation. How do I get previous this? I’m utterly misplaced and I don’t know how I ought to modify my code to observe the documentation any nearer contemplating I’m utilizing SwiftUI and don’t see any documentation that applies any extra so than this. ChatGPT additionally offers me the identical outcomes.
I attempted to make use of callback as an alternative of trailing closure at finish of name, nevertheless this yielded in additional argument ‘callback’ in order that was totally ineffective.
Any try and get round this has additionally resulted in mismatched anticipated values and different annoying looping points which depart me in the identical place each time.
I’m utilizing imports Firebase and GoogleSignIn.