如果引发auth / account-exists-with-different-credential,我会询问什么密码 [英] What password will I ask if auth/account-exists-with-different-credential is thrown

查看:290
本文介绍了如果引发auth / account-exists-with-different-credential,我会询问什么密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况,如果用户首先在我的网络应用程序中使用Google提供商登录后,有时同一用户可能会尝试使用Facebook提供商登录,现在如果用户的Facebook提供商电子邮件ID与以前的Google提供商邮件匹配id在firebase,它会抛出错误,如account-exists-with-different-credential在这种情况下,firebase会给我们Facebook的供应商的电子邮件ID,并指示我们得到询问用户他的密码。我会问他们什么密码,如果用户必须输入Gmail密码,用户才能在第三方网站上输入他们的Gmail密码

在你的情况下,你还会在auth / account-exists-with-different-credential错误(error.credential和error.email)中得到一个电子邮件和凭证对象(facebook凭证)。然后你可以调用

$ p $ auth.fetchProvidersForEmail(error.email)

以获取与该电子邮件对应的现有提供商列表。在这种情况下,你会得到一个数组['google.com']。使用这些提供程序之一,您可以将用户登录到该提供程序。

auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
$ b

您也可以将login-hint:error.email设置为Google提供程序中的自定义OAuth参数。



在用户登录之后,您将之前的Facebook用户信息链接到该用户:
$ b

currentUser.link (error.credential);



现在,您将拥有与现有Google帐户相关联的Facebook帐户。下次用户尝试通过Facebook登录时,错误不会再被抛出。


Here is my scenario, if user sign in with google provider first in my web application following after sometimes the same user may try to login in using facebook provider, now if the user's facebook provider email id matches with the previous google provider mail id in firebase, it will throw error like "account-exists-with-different-credential" in this case firebase will give us the facebook provider email id and instructed us to get the "Asks the user his password." what password will I ask them, if user have to enter the Gmail password will user enter their Gmail password in third party's site

解决方案

In your case, you will also get an email and credential object(facebook credential) in the auth/account-exists-with-different-credential error thrown (error.credential and error.email). You then can call

auth.fetchProvidersForEmail(error.email)

to get the list of existing providers that correspond to that email. In this case you will get an array ['google.com']. Using one of these providers, you sign in the user to that provider.

auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());

You can also set login-hint: error.email as a custom OAuth parameter on the google provider.

After that user is signed in. You then link the previous facebook credential to that user:

currentUser.link(error.credential);

You will now have that facebook account linked to the existing google account. The next time the user tries to login via facebook, the error won't be thrown again.

这篇关于如果引发auth / account-exists-with-different-credential,我会询问什么密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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