本文整理汇总了TypeScript中angular2-jwt.tokenNotExpired函数的典型用法代码示例。如果您正苦于以下问题:TypeScript tokenNotExpired函数的具体用法?TypeScript tokenNotExpired怎么用?TypeScript tokenNotExpired使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tokenNotExpired函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: protectRoute
protectRoute(candidate: TraversalCandidate) {
if (!tokenNotExpired()) {
this.router.go('/login');
return Observable.of(false);
}
return Observable.of(true);
}
示例2: canActivate
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (!tokenNotExpired()) {
this.router.navigate(['/login']);
return Observable.of(false);
}
return Observable.of(true);
}
示例3: appInjector
export const authorize = (to: ComponentInstruction, from: ComponentInstruction, params: Object = {}) =>
{
let injector: Injector = appInjector();
//let router: Router = injector.get(Router);
let user$: Observable<User> = injector.get(UserService).user$
let projects$: Observable<Array<Project>> = injector.get(ProjectsService).projects$
// checks
let authorized = false;
let checkToken = tokenNotExpired(null, localStorage.getItem('token'))
let checkRole$ = user$.map(user => user.role === 'admin' || user.role === params['checkRole'])
let checkGroup$ = projects$
.flatMap(project => project)
.filter(project => project.url === to.urlPath)
.zip(user$)
.map(merged => merged[0].groups.map(projectsGroup => merged[1].groups.indexOf(projectsGroup) !== -1))
.flatMap(merged => merged)
Observable
.merge(checkRole$, checkGroup$)
.filter(check => check === true)
.subscribe
(
(check: boolean) => authorized = check,
err => console.error // maybe redirect to custom 4xx page here...
)
return new Promise((resolve) => resolve(checkToken && authorized))
}
示例4: protectRoute
protectRoute(candidate: TraversalCandidate) {
if (tokenNotExpired('auth_token')) {
return Observable.of(true);
} else {
this._router.go('/login');
return Observable.of(false);
}
}
示例5: canActivate
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (tokenNotExpired()) {
return true;
}
this.router.navigate(['']);
return false;
}
示例6: loggedIn
loggedIn(){
try {
return tokenNotExpired('id_token');
} catch(err) {
this.logout();
return false;
}
}
示例7: canActivate
canActivate() {
if (tokenNotExpired()) {
return true;
}
this.router.navigate(['/startPage']);
return false;
}
示例8: handleError
private handleError(error:any) {
if(!tokenNotExpired()) {
console.debug("NOT LOGGED IN")
return Observable.throw(error);
}
error = error.json() ? {message: error.json().message, status: error.json().status} : error;
console.error('An error occurred', error);
return Observable.throw(error);
}
示例9: constructor
constructor(private http: Http, private router: Router, private _userService: UserService,
private _projectService: ProjectsService)
{
this.date = new Date()
//check whether the user has already logged in...
if (tokenNotExpired(null, localStorage.getItem('token')))
{
this.defaultRedirect()
}
}
示例10: canActivate
canActivate() {
// Check to see if a user has a valid JWT
if (tokenNotExpired()) {
// If they do, return true and allow the user to load the home component
return true;
}
// If not, they redirect them to the login page
this.router.navigate(['/login']);
return false;
}