Logout if token is expired

后端 未结 3 1061
一整个雨季
一整个雨季 2021-01-15 11:28

I\'m working on a react application that consists of many API requests. The structure of the application is

When logging in, I\'m receiving a token on response and I

3条回答
  •  梦谈多话
    2021-01-15 11:46

    Yes you're partially correct, in case you cannot use refresh tokens (which should be given to maintain the login state ideally).

    Use axios interceptors to intercept the response before it becomes an error like 401 which needs to be handled.

    axios.interceptors.response.use(function (response) {
        // 200 type responses, this should be left as it is
        return response;
      }, function (error) {
        // Handle your 401 error, maybe the UI changes and removing from local storage
        return Promise.reject(error);
      });
    

提交回复
热议问题