Maybe you have an idea @jurjen :)
Mar 23, 2017
10
Level 3
Check Laravel login session
Hi,
I want my Vue router to redirect me if the Laravel login session is expired.
Right now i have this 401 code in my store action:
getCustomersIndexData: ({commit, state}) => {
axios.get('/admin/customer/customersApi', {
params: state.customersfilter
}).then(response => {
commit('SET_CUSTOMERS_LIST', response.data);
}).catch((error) => {
// check if unauthorized error returned
if (error.response.status === 401) {
window.location = "/login";
}
});
},
This is not optimal i guess and i would like this 401 code in the rout somehow redirecting user as soon as session expired and user clicks again.
Level 8
Why not just do something like this?
Vue.http.interceptors.push({
response(resp) {
// Check if the user is no longer signed in,
// if so then we need them to sign back in.
if (resp.status === 401) {
window.location.href = '/sign-in';
return;
}
return resp;
}
});
If you want it to continually check at an interval then you can do something as simple as this:
setInterval(() => Vue.$http.get('/api/ping'), 2500);
It is worth noting that if you do this then you may want to elaborate to avoid fighting redirections...
Vue.http.interceptors.push({
response(resp) {
// Check if the user is no longer signed in,
// if so then we need them to sign back in.
if (resp.status === 401) {
clearInterval(window.pinger);
window.location.href = '/sign-in';
return;
}
return resp;
}
});
window.pinger = setInterval(() => Vue.$http.get('/api/ping'), 2500);
1 like
Please or to participate in this conversation.