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

makapaka's avatar

Whats supposed to happen when user session times out

I'm not sure but I'm really surprised I haven't seen this talked about and any solutions for it. But when a user is logged in and walks away until the session is expired - when they come back what is the process of automatically either re-logging them in or showing the login page?

Maybe I've just missed it in my travels around laravel, but everytime it happens with my app, when I come back and click something, it just fails and unless I open the console and see errors, I wouldnt know that I need to refresh the page - not a great UX.

So doesn't Laravel handle this?

0 likes
3 replies
Snapey's avatar

your ajax calls need to handle errors and check if the error is the fact that you are (now) unauthorized

The framework cannot really handle it any other way. A request that requires json is not going to be able to trigger a server specified redirect

2 likes
makapaka's avatar

@Snapey ok that makes sense, but silly question then, how do I redirect to the login page in the JS catch ? I havent seen this discussed in any Jeff's videos yet

Snapey's avatar

I think its window.location() in javascript, and then give it the URL

Please or to participate in this conversation.