【发布时间】:2016-07-24 16:05:05
【问题描述】:
我正在尝试在 Angular.js 2 (2.0.0-rc.4)(由 angular cli 创建)中编写一个路由器保护,等待 AngularFire (2.0.0-beta.2) 检查登录状态并记录如果用户在允许进入状态之前已经登录,则用户(匿名)进入。
我的守护密码是:
canActivate() {
/* This part is to detect auth changes and log user in anonymously */
this.auth
.subscribe(auth => {
if (!auth) {
this.auth.login();
}
});
/* This part is to listen to auth changes and IF there is an auth, resolves this guard with a true to let user in */
return this.auth
.asObservable()
.filter(auth => {
return auth ? true : false;
})
.map(x => {
console.log("TEST 1000");
return true;
});
}
当我运行应用程序时,即使我看到 TEST 1000 控制台输出表明 canActivate() 返回了 true 我的路由没有激活。
我想知道我的逻辑是否有错误的想法,或者有什么聪明的想法可以智能地调试它。
【问题讨论】:
标签: angular firebase rxjs firebase-authentication angularfire2