Answer the question
In order to leave comments, you need to log in
Where to place the logic of “fading out” of the token?
Hello, there is
login: ({ commit, dispatch }, data) =>
new Promise((resolve, reject) => {
apiClient
.post('/auth', data)
.then(resp => {
const { access_token: token, expiryDate } = resp.data;
localStorage.setItem('access_token', token);
apiClient.defaultConfig.headers.Authorization = `Bearer ${token}`;
commit('login', token);
dispatch('getUserInfo');
.....
resolve(resp);
})
.catch(err => {
localStorage.removeItem('access_token');
console.error(err);
reject(err);
});
})
{
login: String,
password: String,
remember: Boolean
}
{
access_token: ...,
expiryDate: YYYY-MM-DD hh:ii:ss
}
if (new Date(expiryDate) >= new Date()) удалить токен...
Answer the question
In order to leave comments, you need to log in
I don't understand why this should be done on the FE side? Let BE know the lifetime of the token, and it will report the fact of decay when requested. You were given a token, you remember it and use it. If, upon request, the server returned a status code about a rotten token, then only then do you make a request to regenerate the token or re-authorize, depending on the specifics of the project.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question