How to redirect to logout when token expired in angular 4

后端 未结 3 2224
北荒
北荒 2021-02-09 06:26

I have a angular 4 application. There i use JWT token for authentication purposes. Everything works fine. but the token expiration time i have given to the JWT token is 1 hour.

3条回答
  •  星月不相逢
    2021-02-09 07:11

    There is tokenNotExpired method in angular2-jwt you can use that to check the token expiration

    Give try on this

      authHttpGet(URL: string): Observable {
        if (!tokenNotExpired('id_token')) {
          this._route.navigate(['login']);
        }
      }
    

提交回复
热议问题