Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jeroenvanrensen's avatar

Vue auth handling when session expires

Hi everyone,

I'm creating an advanced notes app using Laravel and Vue. I use Laravel to login and then redirect to a page where I use VueJS and Axios.

However, if I come back after a while and my session is expired, I can't make Ajax requests anymore, but I also don't get redirected to the login page.

So what can I do about this?

Thank you! Jeroen

0 likes
1 reply
Sergiu17's avatar

Hi,

https://github.com/axios/axios#interceptors

you could check on every request, for example

// values inside if statement are placeholders
if (response.message === 'authentication required') {
	// behave however you want
}

and of course you would search for some articles

https://thedutchlab.com/blog/using-axios-interceptors-for-refreshing-your-api-token

https://medium.com/@yaob/how-to-globally-use-axios-instance-and-interceptors-e28f351bb794

Please or to participate in this conversation.