FirebaseAuth未通过Google身份验证创建新用户-Swift
我正在使用Google身份验证对Firebase上的用户进行身份验证。代码运行时没有错误,但是,我在Firebase控制台的“authentication”选项卡下没有看到任何经过身份验证的用户。根据分析,有用户活动,但没有任何使用谷歌登录的用户记录FirebaseAuth未通过Google身份验证创建新用户-Swift,swift,firebase,firebase-authentication,google-authentication,Swift,Firebase,Firebase Authentication,Google Authentication,我正在使用Google身份验证对Firebase上的用户进行身份验证。代码运行时没有错误,但是,我在Firebase控制台的“authentication”选项卡下没有看到任何经过身份验证的用户。根据分析,有用户活动,但没有任何使用谷歌登录的用户记录 func sign(_signIn: GIDSignIn!, didSignInfor user: GIDGoogleUser!, withError error: Error!){ if let err = error {
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登录”。提前谢谢 我找到了这个问题的答案:
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)
})
}
问题在于第一行代码中的“didsignin”没有正确大写。同样,有一个重复的函数调用同一个登录函数,这可能是另一个问题,即为什么用户没有出现在Firebase控制台的“身份验证”选项卡上
uid
值化了吗?@Kerberos抱歉,最后一部分让人有点困惑。这一行不应该对将用户添加到Firebase控制台上的“身份验证”选项卡产生影响。不,但它可以帮助我们了解它是否已登录。您可以尝试在返回和检查之前添加一些断点。