Angular2 - How to best handle expired authentication token?

前端 未结 5 1397
孤独总比滥情好
孤独总比滥情好 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:28

    Well, reloading is simple: (window).location.reload(true);

    It is good idea to show login/password popup and allow user to continue working if he can provide password, if user hits cancel just do redirect to login page.

    There are also connection problems, timeouts, server errors. The problem is that it is difficult to reliably implement proper handling using Angular 2 Http module and rxjs. Personally, i gave up using Http module, because its error handling has bad design and implemented my own http module, which allows configurable error handling and transparent retries.

提交回复
热议问题