#Redirect user to sign in page when session expires

12 messages · Page 1 of 1 (latest)

shrewd otter
#

How would you guys go about redirecting the user to the sign in page when their session expires? Something that would check every minute or so if their session is still active and then redirect to the home page. Just wanted to see how you'd tackle it.

round lantern
# shrewd otter How would you guys go about redirecting the user to the sign in page when their ...

Don't know exactly how you can run it every minute, but I made something pretty similar using a custom middleware. Check this: https://laravel.com/docs/11.x/middleware#global-middleware. You would have to check your user's session every time that he/she made a HTTP request.

I think Laravel executes the middlewares in the order that you define them though, so pay attention to the order you will put your custom middleware so it doesn't cause any trouble with the native ones

Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.

wispy jay
#

Making a request would just be keeping the session alive tho

slender kestrel
#

You should be able to do it at the route level, so you protect your main pages, if they aren't logged in they go to the sign in page

tribal epoch
#

the Auth::Route will support this functionality as a default func.

shrewd otter
slender kestrel
#

Just use an Auth route so they can only access when logged in

#

You can set the redirect page to what you need it to be

shrewd otter
#

I want them to get redirected to the login page without having to click anywhere

slender kestrel
#

That's how it would work

#

They wouldn't have to click anything it would route them to that page since they are unauthorized