Search code examples
phplaravellaravel-5.5change-passwordlaravel-authentication

Prevent logout after updating user password in Laravel 5.5


Beginning with Laravel 5.3, this middleware was added...

\Illuminate\Session\Middleware\AuthenticateSession

While it's definitely a benefit for security purposes, it's also responsible for logging the user out (presenting the user with the login page) if they change their password.

How do we prevent a user from being logged out (being forced to log back in) when they change their password, in Laravel 5.5?


Solution

  • Instead of changing the middleware, just "re-login" the user after changing the password:

    <?php
    //$user->passwordChangeMagicHere()
    
    Auth::login($user);
    //And the user is logged in again!