[Vuejs]-Vuejs: Routes are accessible even after deleting a token

0๐Ÿ‘

โœ…

So I solved my problem by using axios interceptors. I check if the error status in 401 (Unauthorised) and push router to the login page.

axiosInstance.interceptors.response.use(null, (error) => {
 if (error.response.status === 401) {
  config.token = null;
  router.push({ name: 'login' });
 }
if (error.response.status === 404) {
 router.push({ name: 'error' });
}
 return Promise.reject(error);
});
๐Ÿ‘คOlga B

Leave a comment