How to write a statement in laravel to determine the expiration of a logged-in user's session?
There is an ajax request that can return data when the user logs in. When the session expires, it will jump to the login page. How to do this?
axios.get('/admin/articles')
.then(response=>{
console.log(response.data);
})
.catch(error=>{
console.log(error);
});
Expired, will return
401
status codeBy default, axios will throw
401
toerror
. You can handle the401
status code incatch
and jump to the login page.