AngularFire (2.0.0-rc.4)를 기다리는 Angular.js 2 (2.0.0-rc.4) (각도 cli로 작성)에 라우터 가드를 작성하려고합니다. 0-beta.2)를 사용하여 로그인 상태를 확인하고 사용자가 아직 로그인하지 않은 상태에서 (익명으로) 로그인합니다.AngularFire와 Angularjs에서 auth를 기다리는 라우트 가드 작성 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
콘솔 출력이 true
내 길을 돌아 canActivate()
하는 것은 활성화되지 않음을 나타내는 표시에도 불구하고, 응용 프로그램을 실행합니다.
내 논리에 결함이 있다고 생각하거나 지능적으로 디버깅 할 수있는 멋진 아이디어가 있는지 궁금합니다.
당신이 옳습니다! 내 문제는 실제로, 그것은 완전하지 않았다. 나는'.asObservable()'을'take (1)'로 변경하여 하나의 값만을 기대하고 이후에 완료하면 작업을 시작했습니다! –