vue-authenticate
vue-authenticate copied to clipboard
when reloading site interceptors do not work anymore
I use the following code it works until I reload the site. After reloading it doesn't call the interceptor anymore. What the problem? The token is still there in the session store. After relogin it starts working again until reload. Tested in Safari and Chrome. Using custom auth provider.
/**
* This is example for request and response interceptors for axios library
*/
Vue.use(VueAuthenticate, {
bindRequestInterceptor: function () {
this.$http.interceptors.request.use((config) => {
if (this.isAuthenticated()) {
config.headers['Authorization'] = [
this.options.tokenType, this.getToken()
].join(' ')
} else {
delete config.headers['Authorization']
}
return config
})
},
bindResponseInterceptor: function () {
this.$http.interceptors.response.use((response) => {
this.setToken(response)
return response
})
}
})
There is no bindResponseInterceptor
option anymore. To solve the problem, just setup both request
and response
interceptors inside bindRequestInterceptor
like this
Vue.use(VueAuthenticate, {
bindRequestInterceptor: function () {
this.$http.interceptors.request.use((config) => {
if (this.isAuthenticated()) {
config.headers['Authorization'] = [
this.options.tokenType, this.getToken()
].join(' ')
} else {
delete config.headers['Authorization']
}
return config
})
this.$http.interceptors.response.use((response) => {
this.setToken(response)
return response
})
}
})