var status = 200
let allowRefresh = true
Vue.http.interceptors.push((request, next) => {
if (store.state.userAuth !== null) {
var accessToken = store.state.userAuth.access_token
request.headers.set('Authorization', 'Bearer ' + accessToken)
}
next((response) => {
if (allowRefresh && response.status === 401) {
allowRefresh = false
return user.refresh(request).then(result => {
return Vue.http(request).then(data => {
return data
})
}, () => {
if (user.logout()) {
redirect('/', {
reloadAll: true
})
}
})
} else {
allowRefresh = true
}
// if account creation process is not complete (424)
if (response.status === 424) {
redirect('/user/settings/profile/', {
reloadAll: true
})
}
})
})