gpt4 book ai didi

Firebase 将匿名用户帐户转换为永久帐户错误

转载 作者:行者123 更新时间:2023-12-04 00:30:16 25 4
gpt4 key购买 nike

使用 Firebase for web 我可以成功创建一个匿名用户。我还可以创建一个新的电子邮件/密码用户。但是当尝试将匿名用户转换为电子邮件/密码用户时,我收到错误:

auth/provider-already-linked
User can only be linked to one identity for the given provider.

Firebase 在此处的“将匿名帐户转换为永久帐户”部分下记录了该过程:
https://firebase.google.com/docs/auth/web/anonymous-auth

这是帐户链接代码。匿名用户已登录。
return firebase.auth().createUserWithEmailAndPassword(email, password).then(newUser => {

// Credential is being successfully retrieved. Note "any" workaround until typescript updated.
let credential = (<any>firebase.auth.EmailAuthProvider).credential(email, password);

firebase.auth().currentUser.link(credential)
.then(user => { return user; })
.catch(err => console.log(err)); // Returns auth/provider-already-linked error.
});

最佳答案

您不应调用 createUserWithEmailAndPassword升级匿名用户。这将注册一个新用户,退出当前登录的匿名用户。

您只需要用户的电子邮件和密码。相反,IDP 提供商(例如谷歌、Facebook)将需要完成他们的完整登录流程,以获取他们的 token 来识别用户。我们建议使用 linkWithPopup linkWithRedirect 不过,对于这些。

例子:

// (Anonymous user is signed in at that point.)

// 1. Create the email and password credential, to upgrade the
// anonymous user.
var credential = firebase.auth.EmailAuthProvider.credential(email, password);

// 2. Links the credential to the currently signed in user
// (the anonymous user).
firebase.auth().currentUser.linkWithCredential(credential).then(function(user) {
console.log("Anonymous account successfully upgraded", user);
}, function(error) {
console.log("Error upgrading anonymous account", error);
});

让我知道这是否有效!

关于Firebase 将匿名用户帐户转换为永久帐户错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39088876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com