I was wondering what is the best practise for checking that a user is still logged in client side.
Let's say a user logs in. If it's successfull it will be saved in the state, something like this:
axios.post('/login').then(() => {
this.state.loggedInUser = true
});
Now if a user refreshes their browser, the state is lost, but the laravel_session and XSRF-TOKEN are still available and valid.
Would it make sense to add middleware on every page reload to make a request to retrieve the current logged in user's information? Something like this?:
const authMiddleware = () => {
axios.get('/user').catch(() => console.error('user is not logged in!'));
};
EDIT
Please be aware that I'm using Sanctum in SPA mode. So there's no tokens.