本文整理匯總了TypeScript中ng2-ui-auth.AuthService.isAuthenticated方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript AuthService.isAuthenticated方法的具體用法?TypeScript AuthService.isAuthenticated怎麽用?TypeScript AuthService.isAuthenticated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ng2-ui-auth.AuthService
的用法示例。
在下文中一共展示了AuthService.isAuthenticated方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: intercept
intercept(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
if (!this.auth) {
this.auth = this.injector.get(AuthService);
}
if (this.auth.isAuthenticated()) {
request = request.clone({
setHeaders: {
'X-Auth-Token': this.auth.getToken()
}
});
}
// Add CSRF token for the Play CSRF filter
const token = this.cookieService.get('PLAY_CSRF_TOKEN');
if (token) {
// Play looks for a token with the name Csrf-Token
// https://www.playframework.com/documentation/2.4.x/ScalaCsrf
request = request.clone({
setHeaders: {
'Csrf-Token': token
}
});
}
return next.handle(request);
}
示例2: canActivate
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.auth.isAuthenticated()) {
return true;
}
console.log('unauthenticated navigating to login');
this.router.navigateByUrl('/login');
return false;
}
示例3:
.map((response: Response) => {
let token = response.json() && response.json().token;
console.log(token);
if (typeof token !== 'undefined') {
this.auth.setToken(token);
if (this.auth.isAuthenticated() === true) {
this.getUserDetails();
if (this.user['default_client_id'] !== null) {
this.setDefaultClientId(this.user['default_client_id']);
}
return true;
}
}
return false;
});
示例4: isLoggedIn
isLoggedIn() {
return this.auth.isAuthenticated();
}