【发布时间】:2020-03-14 06:56:50
【问题描述】:
我在我的 Angular 项目中使用简单的电子邮件/密码和谷歌登录 (firebase) 登录身份验证。我想检索当前登录产品的用户的用户 ID (UID)。有没有角度提供检索 UID 的方法?
this.authenticationService.SignUp(this.institutes.email,"123456");
console.log(this.af.auth.currentUser.uid);
SignUp(email: string, password: string) {
this.angularFireAuth
.auth
.createUserWithEmailAndPassword(email, password)
.then(res => {
console.log('You are Successfully signed up!', res);
this.angularFireAuth
.auth
.signInWithEmailAndPassword(email, password)
.then(res => {
console.log('You are Successfully logged in!');
return 1;
})
.catch(err => {
console.log('Something is wrong:',err.message);
});
})
.catch(error => {
console.log('Something is wrong:', error.message);
});
}
我已经注册了一个新帐户并同时登录了该用户。登录后我尝试检索用户的 UID,但收到以下错误: 错误:对象可能为“空”。 错误在线:console.log(this.af.auth.currentUser.uid);
【问题讨论】:
标签: javascript angular firebase firebase-authentication