S
S
Sashqa2020-06-21 18:12:42
Vue.js
Sashqa, 2020-06-21 18:12:42

Checking a token?

Hello, how can I check the token for "liveness" before each request to the API?
During authorization, only access & refresh tokens come, that is, the lifetime does not come

. Found that you can check the token when the application is initialized

created: function () {
      axios.interceptors.response.use(function (response) {
        return response;
      }, function (err) {
        if (err.response?.status === 401 && err.response?.config && !err.response?.config.__isRetryRequest) {
          store.dispatch(LOGOUT)
        }
        throw err;
      });
    }


And how to check it with each request to the API?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
coderisimo, 2020-06-21
@Sashqa

When you receive it is the time of its creation. Next, before sending, find the difference between the current time and the time it was created.
Or you can not check the lifetime of the token . Just if you get an error in the server response -
if (err.response.status === token expired ....
- you get a new one using a refresh token.

N
neomichi, 2020-06-22
@neomichi

You can, as an option, through cookies
+ lifetime.
-live refresh token (session cookie is out, but.....)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question