我正在使用VueJS和Firebase Auth(NPM - 版本5.6.0)。我需要将匿名用户转换为Google作为提供商的注册用户。我尝试了recently updated sample from the Firebase docs:
anonymousToGoogle: function () {
var googleUser
var provider
var credential = firebase.auth.GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token)
firebase.auth.currentUser.linkWithRedirect(provider)
firebase.auth().currentUser.linkAndRetrieveDataWithCredential(credential).then(function (usercred) {
var user = usercred.user
console.log('Anonymous account successfully upgraded', user)
}, function (error) {
console.log('Error upgrading anonymous account', error)
})
}
}
Button(使用VuetifyJS框架):
<v-btn block @click="anonymousToGoogle()">CONVERT - Login with Google</v-btn>
单击按钮后,控制台显示此错误:
[Vue警告]:“click”的事件处理程序出错:“TypeError:不能 读取属性'getAuthResponse'未定义“
答案 0 :(得分:1)
您只需在匿名用户上拨打linkWithRedirect
即可。
// Assuming you previously signed in anonymously.
firebase.auth().signInAnonymously().then(function(result) {
var provider = new firebase.auth.GoogleAuthProvider();
// Page will redirect to google and then back. You can get back
// result via getRedirectResult().
return firebase.auth().currentUser.linkWithRedirect(provider);
}).catch(function(error) {
// Error occurred.
});