使用 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 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 提供商(例如 Google、Facebook)将要求完成完整的登录流程,以获得令牌来识别用户。我们建议使用linkWithPopup https://firebase.google.com/docs/reference/js/firebase.User#linkWithPopup or linkWithRedirect https://firebase.google.com/docs/reference/js/firebase.User#linkWithRedirect不过对于这些。
Example:
// (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);
});
让我知道这是否有效!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)