本文整理汇总了TypeScript中angularfire2.FirebaseAuth.take方法的典型用法代码示例。如果您正苦于以下问题:TypeScript FirebaseAuth.take方法的具体用法?TypeScript FirebaseAuth.take怎么用?TypeScript FirebaseAuth.take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angularfire2.FirebaseAuth
的用法示例。
在下文中一共展示了FirebaseAuth.take方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: canActivate
/**
* To protect routes from being accessible without authentication, the `canActivate()` method checks that current
* user has been authenticated via FireBaseAuth service and current auth state is valid. Only then navigation will
* pass on the requested route. Otherwise user will be redirected to login page.
*
* @returns {Observable<boolean>}
*/
canActivate(): Observable<boolean> {
return this.auth
.take(1)
.map((authState: FirebaseAuthState) => {
!!authState ? localStorage.setItem('uid', authState.uid) : localStorage.removeItem('uid');
return !!authState;
})
.do(authenticated => {
if (!authenticated) {
this.router.navigate(['/login']);
}
})
;
}
示例2: canActivate
canActivate() {
return this._fbAuth
.take(1)
.map(auth => !!auth);
}