在 Firebase 中使用 Google 身份验证未收到电子邮件 [英] Not getting the email using Google Authentication in Firebase

查看:45
本文介绍了在 Firebase 中使用 Google 身份验证未收到电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Firebase 提供的代码进行 Google 身份验证,不知何故,身份验证成功,但电子邮件未正确导入 Firebase.

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {如果让错误 = 错误 {打印(错误.本地化描述)返回}让身份验证 = user.authentication让凭证 = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken,accessToken: authentication.accessToken)FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in如果错误 != nil {打印(错误?.localizedDescription)返回}print("用户使用谷歌登录...")self.performSegueWithIdentifier("ToHome", sender: nil)}}

解决方案

电子邮件未显示在 firebase 控制台上,因为您允许用户使用同一电子邮件创建多个帐户.如果您导航到 Auth ->登录方法您可以将选项设置为避免使用同一电子邮件创建多个帐户.这样做之后,电子邮件将在创建用户时开始出现.

这里不确定,但是如果您仍想创建多个帐户并在应用程序端拥有用户电子邮件,我想您在创建用户时需要将电子邮件存储在 firebase 数据库中.

I am using the code provided by Firebase for Google Authentication and somehow, the authentication was successful but the email was not correctly imported to Firebase.

https://firebase.google.com/docs/auth/ios/google-signin

As you can see in the screenshot below, the email is blank. When I looked at the debugger, it is showing nil.
I clicked allow viewing email during authentication but I think there are still some settings that was not done correctly. Could someone help me to take a look? I am interested to use the email to create the username for each user.

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
    if let error = error {
        print(error.localizedDescription)
        return
    }

    let authentication = user.authentication
    let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken,
                                                                 accessToken: authentication.accessToken)
    FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
        if error != nil {
            print(error?.localizedDescription)
            return
        }

        print("User logged in with Google...")
        self.performSegueWithIdentifier("ToHome", sender: nil)
    }
}

解决方案

The email is not showing on firebase console because you are allowing users to create multiple accounts with the same email. If you navigate to Auth -> Sign-in method you can set the option to Avoid creating multiple accounts with the same e-mail. After doing so the emails will start to appear when creating the user.

Not sure here but, if you still want to create multiple accounts and have the user email on the application side I guess that you will need to store the email on firebase database when creating the user.

这篇关于在 Firebase 中使用 Google 身份验证未收到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆