为什么我无法将Firebase电子邮件密码登录链接到Google登录? [英] Why can't I link firebase email-password sign-in to google sign-in?
问题描述
我已经在我的帐户中成功实现了 Firebase Google登录android应用程序,它可以正常工作.但是,我希望用户也使用电子邮件和密码登录应用程序.因此,我按照本教程将google登录与电子邮件密码登录.但是,当我尝试使用以下代码登录电子邮件密码时:
I have successfully implemented Firebase Google Sign-In in my android app and it works fine. But, I want the users to login into the app using email and password also. So, I followed this tutorial to link the google sign-in with email-password sign-in. But, when I try to sign-in with email-password with the following code:
firebaseAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>()
{
@Override
public void onComplete(@NonNull Task<AuthResult> task)
{
if (task.isSuccessful())
{
//code to link accounts
}
else
{
Toast.makeText(context, "SIgn In Error", Toast.LENGTH_SHORT).show();
System.out.println("SIGN IN: " + task.getException());
}
}
});
它显示了例外情况:
com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The password is invalid or the user does not have a password.
代码有什么问题?
推荐答案
从错误消息中看来,您正在为尚未创建的用户调用 signInWithEmailAndPassword
.
From the error message it seems like you're calling signInWithEmailAndPassword
for a user that was not created yet.
您只能调用 signInWithEmailAndPassword(电子邮件,密码)
登录以前使用 createUserWithEmailAndPassword(电子邮件,密码)
创建的用户.您明确不能使用它登录以前仅使用其他身份提供商(例如Google登录)登录/创建的用户.
You can only call signInWithEmailAndPassword(email, password)
to sign in a user that was previous created with createUserWithEmailAndPassword(email, password)
. You explicitly can't use it to sign in a user that was previous only signed in/created with another identity provider, such as Google sign-in.
如果您希望允许通过Google登录的同一用户也使用您的应用专用密码登录,则还需要创建这些辅助凭据,然后创建
If you want to allow the same user who signed in through Google, to also sign in with a password that is specific to your app, you will need to also create those secondary credentials, and then link the two providers (Google + Email/Password).
这篇关于为什么我无法将Firebase电子邮件密码登录链接到Google登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!