當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。