本文整理匯總了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);
}