D
D
dicem2021-01-09 17:02:25
JSON Web Token
dicem, 2021-01-09 17:02:25

How to implement token refresh on Nuxt/Vue?

I am making a site on Nuxt, if everything is clear with API authorization, we get a token and store it, then what about the refresh token? Suppose we have a date when the main token stops working and the time has come to update it, how to check this? Check token date via setInterval? Or through each page transition through beforeEach?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Golub, 2021-01-10
@dicem

I did it through axios and the general handler, in the case of a non-working token, sent an error like 405 (for example). At the front, this error was set by the action of sending a refresh token, if it was erroneously thrown out of the system. If ok, then I updated the access token and made the request again.
https://axios.nuxtjs.org/extend

A
Alexey, 2021-01-09
@AlexeyCaTHaR

Kmk should be hung on the hook. What's the point of making requests if the content doesn't change?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question