我正在使用Ionic2 rc4和Firebase身份验证。如果我拨打signupFirebaseUser()
,它会按预期记录uid
。但是,当我打电话给loginGoogle()
时,我希望它记录一个不同的uid
,但它打印相同uid
。Firebase登录 - 如何重置uid?
这意味着用户不能与email address
和password
登录,注销,然后重新与他们的谷歌帐户(不同的电子邮件地址)登录,因为它要保留他们的老uid
。
signupFirebaseUser(email: string, password: string): firebase.Promise<any> {
return this.fireAuth.createUserWithEmailAndPassword(email, password).then((newUser: firebase.User) => {
console.log(newUser.uid);
this.userProfile.child(newUser.uid).set({ email: email });
newUser.sendEmailVerification();
});
}
然后
public logout(auth: FirebaseAuth, fireAuth: firebase.auth.Auth): Promise<any> {
return auth.logout().then(() => {
fireAuth.signOut().then(() => {
});
});
}
然后
loginGoogle() {
this.auth.login({
provider: AuthProviders.Google,
method: AuthMethods.Popup
}).then((data: FirebaseAuthState) => {
console.log(data.uid);
}).catch((error) => {
console.error('loginGoogle', error);
});
}
问题
你如何重置火力地堡认证忘记老uid
?所以当你再次登录时,你可以从干净的开始。
即生成每个供应商(谷歌,Facebook,电子邮件)的新uid
。
任何帮助表示赞赏。
一种方法可以使用user.delete()来删除用户,然后重新创建它会自动有一个新的UID – AndroidBeginner
是的,你是正确的,将工作。但是如果您想再次以旧用户的身份重新登录(即继续交换用户),会发生什么情况?我不想删除该帐户,因为我针对每个用户存储了数据。 – Richard
对不起,误解了这个问题。您可以尝试将新的Firebase Auth API用于Google登录吗? (https://firebase.google.com/docs/auth/web/google-signin)。如果您需要Cordova支持,则可以使用OAuth插件(例如https://github.com/nraboy/ng-cordova-oauth),然后使用返回的访问令牌调用signInWithCredential()。 –