Regarding API TOKEN mechanism, what should be done if token expires?


Front vue
Interacting with backend via API
The token mechanism is used for authentication.
If the backend in the user request judges that the token has expired or is invalid
How should the front end handle it?
Can axios focus on this requirement?
Or does every ajax request have to bring a token expired service?

Two questions

  1. How to deal with the expiration of general token?
  2. The front-end processing of token expiration means that each ajax request determines whether the server returns token expiration and then what to do?

The expired back end can clear it by itself, and the front end will clear it automatically if you have cookie expiration.
The front end processes all requests through the axios interceptor

// http response interceptor
 response => {
 return response;
 error => {
 if (error.response) {
 switch (error.response.status) {
 case 401:
 //jump here and log in