在Angular4 + Firebase 3.x中寻找指导
使用案例:
此阶段用户注销并再次通过FB登录用户将在Firebase中注册并重定向到其他信息屏幕。如果用户输入相同的电子邮件ID,则Firebase会引发错误。当我尝试将新的FB登录链接到G + id时,我收到以下错误。
updateFBUserInfo() {
let user = firebase.auth().currentUser;
let userEmail = this.userInfo.email;
const provider = new firebase.auth.FacebookAuthProvider();
user.updateProfile({
displayName: this.userInfo.displayname,
photoURL: this.userInfo.photoURL
}).then(function() {
// Update successful.
user.updateEmail(userEmail).then(function() {
console.log('Update successful.');
}, function(error) {
console.log('EMAIL UPDATE ERROR: ' + error);
firebase.auth().currentUser.linkWithRedirect(provider).then(function () {
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
this.credential = result.credential;
var user = result.user;
}
}).catch(function(error) {
console.log('REDIRECT Error: ' + error);
});
}).catch(function(error) {
console.log('LINK Error :' + error);
})
});
}, function(error) {
console.log('CREDENTIAL ERROR :' + error);
// Get reference to the currently signed-in user
var prevUser = firebase.auth().currentUser;
// Sign in user with another account
firebase.auth().signInWithCredential(this.credential).then(function(user) {
console.log("Sign In Success", user);
var currentUser = user;
// Merge prevUser and currentUser accounts and data
// ...
}).catch(function(error) {
console.log("Sign In Error", error);
});
});
}
提前致谢。