【发布时间】:2018-01-17 07:04:59
【问题描述】:
我已经为我的 Angular 2 应用程序构建了一个身份验证。我通过使用 Firebase 身份验证服务实现了这一点。重新加载页面后,用户退出,但令牌仍然存在于 localStorage 中。
这是我的代码:
export class AdminService {
email;
password;
error;
invalidLogin;
isLoggedIn = false;
constructor(private af: AngularFireAuth,private router: Router,private route: ActivatedRoute) {
}
login(){
this.af.auth.signInWithEmailAndPassword(this.email,this.password)
.then(authState => {
if(authState){
let returnUrl = this.route.snapshot.queryParamMap.get('returnUrl');
this.router.navigate([returnUrl||'/']);
this.isLoggedIn = true;
}
else this.invalidLogin = true;
})
}
logout(){
this.af.auth.signOut();
this.isLoggedIn = false;
this.router.navigate(['/'])
}
}
【问题讨论】:
标签: angular typescript firebase firebase-authentication angularfire2