[Vuejs]-Remove token in frontend using Vue JS after deleting it from database in backend with Laravel?

1👍

I’m not sure if i got the question right, but you would normalle use an axios interceptor like so:

_axios.interceptors.response.use(
  response => response,
  error => {
        
    if (error.response.status === 401) {
      console.log('Intercept: 401 - Unauthenticated')
      //DELETE THE TOKEN FROM STORAGE AND FROM AXIOS HEADER
      delete window.axios.defaults.headers.common.Authorization
      localStorage.removeItem('token')

      return router.replace({ name: 'login' })
    }
    if (error.response.status === 403) {
      console.log('Intercept: 403 - Unauthorized')
    }
    if (error.response.status === 422) {
      console.log('Intercept: 422 - Validation Error')
    }
        
    return Promise.reject(error)
  },
)

Leave a comment