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

jcalonso's avatar

Restore session data after remember me auth

Normally when a user logs into my application I set some session variables in the AuthController->authenticated() method. The problem that I'm having is when a user has the remember me option enabled and the session expires, Laravel will re-authenticate the user but it will miss setting the session data making my application to crash since i need the data from the session.

Where is the best place to put this session logic so that it trigger in both cases (normal auth and remember me) ? I was thinking on listening to an auth event. but I'm not very sure.

Thanks in advance.

0 likes
2 replies
SaeedPrez's avatar
Level 50

Perhaps create a global middleware that checks if the user is authenticated and if they have the session data, if not it sets the session data.

1 like
jcalonso's avatar

Yeah good idea!, I was over complicating the problem.

Cheers!

Please or to participate in this conversation.