当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript JwtHelper.isTokenExpired方法代码示例

本文整理汇总了TypeScript中angular2-jwt.JwtHelper.isTokenExpired方法的典型用法代码示例。如果您正苦于以下问题:TypeScript JwtHelper.isTokenExpired方法的具体用法?TypeScript JwtHelper.isTokenExpired怎么用?TypeScript JwtHelper.isTokenExpired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在angular2-jwt.JwtHelper的用法示例。


在下文中一共展示了JwtHelper.isTokenExpired方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: ngOnInit

  // Checks for token expiration to display appropriate page
  ngOnInit() {
  var jwtHelper = new JwtHelper();
  var token = localStorage.getItem('auth_token');
  if (token) {
    console.log(jwtHelper.isTokenExpired(token));
    if (jwtHelper.isTokenExpired(token)) {
    this.router.navigate(['/']);
    } else {
    this.router.navigate(['/home']);
    }
  } else {
    this.router.navigate(['/']);
  }

  }
开发者ID:andela-jmwangi,项目名称:Masdu,代码行数:16,代码来源:app.component.ts

示例2:

		tokenGetter: () => {
			// Look in session storage for id_token, but fallback to local storage
			let session = sessionStorage.getItem('id_token');
			let local = localStorage.getItem('id_token');

			let token = session || local;

			if (typeof token !== 'string') { return ''; }

			// Remove any quotations from the sides
			token = token.split('"').join('');

			// Check validity of jwt token
			if (token.split('.').length !== 3) {
				localStorage.removeItem('id_token');
				sessionStorage.removeItem('id_token');
				return '';
			}

			// Check if token is expired. If it is, delete and send user to login page
			if (jwtHelper.isTokenExpired(token)) {
				sessionStorage.removeItem('id_token');
				localStorage.removeItem('id_token');

				this.router.navigate(['/login']);
				return '';
			}

			return token;
		},
开发者ID:michaelgira23,项目名称:MyMICDS-v2-Angular,代码行数:30,代码来源:app.module.ts

示例3: isTokenValid

 isTokenValid(token: string): Boolean {
 //   auth0 = new auth0.WebAuth({
 //   clientID: AUTH_CONFIG.CLIENT_ID,
 //   domain: AUTH_CONFIG.CLIENT_DOMAIN
 // });
   const jwtHelper: JwtHelper = new JwtHelper();
   return jwtHelper.isTokenExpired(token);
 }
开发者ID:riyan10dec,项目名称:FlexerCMS2,代码行数:8,代码来源:jwt.service.ts

示例4: canActivate

  canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    if (window.localStorage.getItem('token') &&
      !jwtHelper.isTokenExpired(window.localStorage.getItem('token'))) {
      return true;
    }

    this.router.navigate(['login']);
    return false;
  }
开发者ID:Sirimangalo,项目名称:meditation-plus-angular,代码行数:9,代码来源:auth-guard.ts

示例5: isAuthenticated

    isAuthenticated(): boolean {
        let jwt = this.jwtStorage.getToken();

        if (null === jwt) {
            return false;
        }

        return !this.jwtHelper.isTokenExpired(jwt.token);
    }
开发者ID:Invis1ble,项目名称:assistant-client,代码行数:9,代码来源:auth.service.ts

示例6: canActivate

  canActivate() {
    var token = localStorage.getItem("jwt");
 
    if (token && !this.jwtHelper.isTokenExpired(token)){
        console.log(this.jwtHelper.decodeToken(token));
        return true;
    }
    this.router.navigate(["login"]);
    return false;
  }
开发者ID:joeymalouf,项目名称:GraduationGuideline,代码行数:10,代码来源:auth-gaurd.service.ts

示例7: tokenNotExpired

	public static tokenNotExpired(tokenName?: string, jwt?: string) {

		var authToken: string = tokenName || 'id_token';
		var token: string;

		if (jwt) {
			token = jwt;
		} else {
			token = localStorage.getItem(authToken);
		}

		var jwtHelper = new JwtHelper();

		if (!token || jwtHelper.isTokenExpired(token, null)) {
			return false;
		} else {
			return true;
		}
	}
开发者ID:mursch,项目名称:sb-ui,代码行数:19,代码来源:AuthUtils.ts

示例8: canActivate

	canActivate() {
		// Look in session storage for id_token, but fallback to local storage
		let session = sessionStorage.getItem('id_token');
		let local = localStorage.getItem('id_token');

		let token = session || local;

		// If there is a token, then user is logged in, otherwise redirect to login page
		if (token && !jwtHelper.isTokenExpired(token)) {
			return true;
		}

		// Delete JWT from the client just in case it was simply expired
		sessionStorage.removeItem('id_token');
		localStorage.removeItem('id_token');

		this.router.navigate(['/login']);
		return false;
	}
开发者ID:michaelgira23,项目名称:MyMICDS-Mobile,代码行数:19,代码来源:auth.guard.ts

示例9: tokenExpired

    tokenExpired() {

        let token = localStorage.getItem('id_token');

        return this.jwtHelper.isTokenExpired(token);
    }
开发者ID:ecos-codeaholics,项目名称:factory-of-procedures-front,代码行数:6,代码来源:jwt-helper.service.ts

示例10: isLoggedIn

  public isLoggedIn(): boolean {
    let token = localStorage.getItem('auth_token')
    let isLoggedIn = token && !this.jwtHelper.isTokenExpired(token);

    return isLoggedIn;
  }  
开发者ID:steelheaddigital,项目名称:angular2-express-starter,代码行数:6,代码来源:auth.service.ts


注:本文中的angular2-jwt.JwtHelper.isTokenExpired方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。