I can't configure Google SignIn with Firebase on my Xcode

94 Views Asked by At

I'm trying to configure my Google SignIn in my Swift project but I can't call the clientID. Yesterday it showed "This property is defined on FirebaseOptions, and may not be available in this context." Today it says "This property is defined on GIDConfiguration, and may not be available in this context."

enter image description here

It seems to me that this is some error on the package import of Firebase or GoogleSignIn? I did all the steps to download the packages, so I don't know what's wrong. My GoogleService-Info.plist it's on the project. Also I did an email and password login setup with Firebase and worked right, but this FirebaseApp.configure() expression is not highlighted so it's itching me something too.

I'm on Xcode 15.0.1, macOS Sonoma 14.0.

Thanks!

1

There are 1 best solutions below

0
Andy On

The clientID property has been moved to FirebaseOptions, you can access the clientID and start the sign-in flow like this:

@MainActor
func getGoogleAuthCredential() async throws -> AuthCredential {
    let clientID = FirebaseApp.app()!.options.clientID!
    GIDSignIn.sharedInstance.configuration = GIDConfiguration(clientID: clientID)
    let rootVC = UIApplication.shared.windows.first!.rootViewController!
    let result = try await GIDSignIn.sharedInstance.signIn(withPresenting: rootVC)
    let idToken = result.user.idToken!.tokenString
    let accessToken = result.user.accessToken.tokenString
    let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: accessToken)
    return credential
}

For more information, see this quick migration guide