【发布时间】:2021-04-06 17:23:01
【问题描述】:
如何在AuthService 中添加loginIn 方法,以便获得有关用户状态的布尔值?我想要它用于CanActivate 方法,AuthService 看起来像这样:
login(email: string, password: string) {
return this.http.post<AuthResponseData>(
'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=',
{
email,
password,
returnSecureToken: true
}
)
.pipe(tap(resData => {
this.handleAuthentication(
resData.email,
resData.localId,
resData.idToken,
+resData.expiresIn);
})
);
}
// tslint:disable-next-line:typedef
private handleAuthentication(
email: string,
userId: string,
token: string,
expiresIn: number) {
const expirationDate = new Date(new Date().getTime() + expiresIn * 1000);
const user = new User(
email,
userId,
token,
expirationDate
);
this.user.next(user);
}
【问题讨论】:
标签: angular typescript firebase