Angular2 - How to best handle expired authentication token?

前端 未结 5 1390
孤独总比滥情好
孤独总比滥情好 2021-02-05 11:06

I am using Angular 2.1.2.

I have an authentication token (using angular2-jwt) and if it expires my webApi call fails with a 401 error. I am looking for a solution where

5条回答
  •  轮回少年
    2021-02-05 11:31

    Ideally, the request would just 'pause' until the user logs in from the modal. I have not found a way to implement this.

    Did you try to switch your button by using tokenNotExpiredattribute like in this example : https://github.com/auth0/angular2-jwt#checking-authentication-to-hideshow-elements-and-handle-routing

    It allows you to prevent the 401...

提交回复
热议问题