【问题标题】:FirebaseAuth not creating new user from Google authentication - SwiftFirebaseAuth 未通过 Google 身份验证创建新用户 - Swift
【发布时间】:2018-11-20 22:55:36
【问题描述】:

我正在使用 Google 身份验证对 Firebase 上的用户进行身份验证。代码运行没有错误,但是,我在 Firebase 控制台的“身份验证”选项卡下看不到任何经过身份验证的用户。根据分析,存在用户活动,但没有任何使用 Google 登录的用户的记录。

 func sign(_signIn: GIDSignIn!, didSignInfor user: GIDGoogleUser!, withError error: Error!){
    if let err = error {
        print ("failed to log into Google", err)
        return
    }
    guard let authentication = user.authentication else { return }

    let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
                                                   accessToken: authentication.accessToken)


    Auth.auth().signInAndRetrieveData(with: credential, completion: { (authResult, error) in
        if let error = error {
            print ("failed to create with google account")
            return
        }
       // User is signed in
        guard let uid = user?.userID else {
            return

        }

我遵循了 Firebase 上的文档并启用了“Google 登录”。提前致谢!

【问题讨论】:

  • uid 是否已增值?
  • @Kerberos 抱歉,最后一部分让它有点混乱。该行不应影响将用户添加到 Firebase 控制台上的“身份验证”选项卡。
  • 不,但它可以帮助我们了解它是否有登录。可以尝试在返回前加一些断点检查一下。

标签: swift firebase firebase-authentication google-authentication


【解决方案1】:

我找到了问题的答案:

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!){
    if let err = error {
        print ("failed to log into Google", err)
        return
    }

    print("successfully logged into Google",user)
    guard let idToken = user.authentication.idToken else {return}
    guard let accessToken = user.authentication.accessToken else {return}
    let credentials = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: accessToken)


    Auth.auth().signInAndRetrieveData(with: credentials, completion: { (user, error) in
        if let err = error {
            print ("failed to create with google account", err)
            return
        }
        print("successfuly logged into Firebase with Google", user?.user.uid)





})


    }

问题在于第一行代码,其中“didSignInFor”没有正确大写。同样,有一个重复的函数调用了相同的登录函数,这可能是用户没有出现在 Firebase 控制台的“身份验证”选项卡上的另一个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    • 2015-02-24
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    相关资源
    最近更新 更多