Ayd*_*hew 12 firebase firebase-authentication
使用Firebase for web我可以成功创建匿名用户.我还可以创建一个新的电子邮件/密码用户.但是当尝试将匿名用户转换为电子邮件/密码用户时,我收到错误:
auth/provider-already-linked
User can only be linked to one identity for the given provider.
Run Code Online (Sandbox Code Playgroud)
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.
});
Run Code Online (Sandbox Code Playgroud)
TMS*_*SCH 23
您不应该致电createUserWithEmailAndPassword
升级匿名用户.这将注册一个新用户,注销当前已登录的匿名用户.
您只需要用户的电子邮件和密码即可.相反,IDP提供商(例如谷歌,Facebook)需要完成他们的完整登录流程才能让他们的代币识别用户.不过,我们建议使用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);
});
Run Code Online (Sandbox Code Playgroud)
如果有效,请告诉我!
归档时间: |
|
查看次数: |
5069 次 |
最近记录: |