Currently, I am utilizing Vue.js
along with axios
in an attempt to create a generic API object as shown below:
import router from './router'
import auth from './auth'
const axios = require('axios')
export const API = axios.create({
baseURL: `https://my-api.com/`,
headers: {
Authorization: auth.getToken()
}
})
API.interceptors.response.use(null, function (error) {
if (error.response.status === 401) {
console.log('Failed to login')
router.push('/Login')
}
return Promise.reject(error)
})
The goal is to automatically redirect users to the Login
screen within my single-page application whenever a 401
error code is received. However, despite receiving the console.log
message of Failed to login
, there is no redirection taking place and no errors are detected in Chrome's Developer Tools.