I am using Laravel + Vue + Vue Router.
How to you handle the TokenMismatchException in Vue after the XSRF-token expired? How to you reset the token after it expired?
Should I use an interceptor and redirect to refresh the page and redirect to login?
axios.interceptors.response.use(function (response) {
return response
}, function (error) {
if (Cookies.get('XSRF-TOKEN') === undefined) {
window.location = '/login';
return Promise.reject('')
}
})
Or is it possible to have the interceptor rather request a new XSRF-token from an endpoint (www.mysite.com/token) so that the page does not need to be refreshed? How would you do this?
axios.interceptors.response.use(function (response) {
return response
}, function (error) {
console.log(Cookies.get('XSRF-TOKEN') === undefined)
if (Cookies.get('XSRF-TOKEN') === undefined) {
axios.get('/token')
.then(response => {
/// Do something?
})
return Promise.reject('')
}
})
Is there another way?