[英]Firebase account linking error
So when you try to login to an app using some other auth method, for example at first the user used Google and now he using FB and those 2 accounts have the same mail, you get that error 因此,当您尝试使用其他身份验证方法登录应用程序时,例如,首先用户使用Google,而现在他使用FB,并且这两个帐户具有相同的邮件,则会收到该错误
auth/email-already-exists
The thing is, that if you have 3+ auth methods, that error message isnt very specific and it could be a little tricky to develop a logic that handles this situation. 问题是,如果您具有3+身份验证方法,则该错误消息不是非常具体,开发处理这种情况的逻辑可能会有些棘手。 How do you solve this issue?
您如何解决这个问题?
email-already-exists is thrown in the firebase-admin sdk. 电子邮件已经存在将被抛出到firebase-admin sdk中。 I don't think it is thrown in the client SDK.
我认为客户端SDK中不会抛出该错误。 For the client SDK, the following errors would be thrown when linking an existing account to another one, or signing in with a new account where the email exists in another one:
对于客户端SDK,将现有帐户链接到另一个帐户,或使用另一个帐户中存在电子邮件的新帐户登录时,将引发以下错误:
In all of the above, the error may contain the additional fields: 在上述所有情况下,该错误可能包含其他字段:
You can lookup the existing account to find out what providers exist for it: 您可以查找现有帐户以查找为其提供了哪些提供程序:
firebase.auth().fetchProvidersForEmail(error.email)
.then(function(providers) {
// Providers would be an array of the form:
// ['password', 'google.com']
});
For auth/account-exists-with-different-credential, you can then sign in with that provider and if needed link the error.credential to the signed in user. 对于auth / account-exists-with-different-credential,您可以使用该提供程序登录,然后根据需要将error.credential链接到已登录的用户。
firebase.auth().currentUser.link(error.credential);
If the error occurred when linking (auth/credential-already-in-use), you can directly sign in with that credential 如果链接时发生错误(身份验证/凭据已在使用中),则可以直接使用该凭据登录
firebase.auth().signInWithCredential(error.credential):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.