This is my refresh token plugin
refresh_token.js
const axiosOnResponseErrorPlugin = ({ app, $axios, store }) => {
$axios.onResponseError(err => {
const code = parseInt(err.response && err.response.status)
let originalRequest = err.config
if (code === 401) {
originalRequest.__isRetryRequest = true
const refreshToken = store.state.auth.refresh_token ? store.state.auth.refresh_token : null
if (refreshToken) {
return new Promise((resolve, reject) => {
$axios.post('refresh-token/', {
refresh: refreshToken
})
.then((response) => {
if (response.status === 200) {
let auth = response.data
err.response.config.headers['Authorization'] = `${auth.access}`
}
resolve(response)
})
.catch(e => {
// should jump here after facing error from request
reject(e)
})
})
.then((res) => {
return $axios(originalRequest)
})
.catch(e => {
app.router.push('/')
})
}
}
})
}
export default axiosOnResponseErrorPlugin
My problem is, if refresh token is not expired then it's working fine, but if it is expired then it should redirect to a page which is not doing right now. I couldn't find any way to redirect/push to another router after expiration.
Have any suggestion ?