Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force logout when following reset password path

Tags:

laravel-5

I have a working password reset process with the following routes:

Route::group(['middleware' => [], 'namespace' => 'Auth'], function () {
    Route::get('/password/reset/{token?}', ['as' => 'site.password.showResetForm', 'uses' => 'PasswordController@showResetForm']);
    Route::post('/password/email', ['as' => 'site.password.sendResetLinkEmail', 'uses' => 'PasswordController@postEmail']);
    Route::post('/password/reset', ['as' => 'site.password.reset', 'uses' => 'PasswordController@reset']);
});

My problem arises if someone is currently already logged in on the machine. In that case when A user clicks on the link in the email, PasswordController@showResetForm is never executed and the their home page opens in a new tab. Is there a way to force the current user to be logged out so that the password reset can proceed?

like image 840
WombatPM Avatar asked Sep 20 '25 16:09

WombatPM


1 Answers

Call Auth::logout(); in one of your controllers.

If the showResetForm is never displayed due to user being logged in, you will need to create a temporary page where you call the above function and then redirect to Password Reset page:

public function do_password_reset()
{
    Auth::logout();
    return redirect()->route('PasswordController@showResetForm');
}

(Remember to add the relevant route for this function.)

like image 192
Niraj Shah Avatar answered Sep 23 '25 12:09

Niraj Shah