FirebaseAuth没有通过Google身份验证创建新用户 - Swift

时间:2018-06-11 16:11:48

标签: swift firebase firebase-authentication google-authentication

我正在使用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登录”。提前谢谢!

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案:

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控制台的选项卡。