i want to use Auth::logoutOtherDevices($currentPassword) in laravel 8 to logout user from other devices after changing password. As per documentation ia have uncomment the line \Illuminate\Session\Middleware\AuthenticateSession::class,. But unfortunately, it's not working. It says Method Illuminate\Auth\RequestGuard::viaRemember does not exist. Can anyone please help me to sort it out how can i add logout from other devices functionality with the help of Auth::logoutOtherDevices($currentPassword) or any manual method ?
Here is my code:
$rules = [
'currentpass' => 'required',
'newpass' => 'required|min:6',
'confnewpass' => 'required|same:newpass|min:6'
];
$messages = [
'currentpass.required' => 'Please enter your current password.',
'newpass.required' => 'Please provide a new password.',
'newpass.min' => 'Password must contain minimum 6 characters.',
'confnewpass.required' => 'Please provide your new password again to confirm.',
'confnewpass.same' => 'Both new passwords must be same.',
'confnewpass.min' => 'Password must contain minimum 6 characters.'
];
$this->validate($request, $rules, $messages);
$currentPass = $request->input('currentpass');
$newPass = $request->input('newpass');
try {
$user = User::findOrFail(Auth::id());
} catch (ModelNotFoundException $ex) {
$response['error'] = true;
$response['errors']['notFound'] = ['User Not Found.'];
return response()
->json($response, 400, [], JSON_PRETTY_PRINT);
}
if (!Hash::check($currentPass, $user->password)) {
return Redirect::back()
->withErrors(['Current Password', 'Please provide your current password properly.']);
}
$isChar = preg_match('/[a-zA-Z]+/', $newPass);
$isNum = preg_match('/\d+/', $newPass);
if (!($isChar && $isNum)) {
$response['error'] = 'Password must contain minimum 6 characters with at-least one letter and one number.';
return response()
->json($response, 200, [], JSON_PRETTY_PRINT);
}
/** hash password */
$hashpass = Hash::make($newPass);
$user->password = $hashpass;
try {
$user->save();
} catch (QueryException $ex) {
return Redirect::back()
->withErrors(['query', $ex->getMessage()]);
}
Auth::logoutOtherDevices($currentPass);
return Redirect::back()
->with('success', 'Your password has been successfully updated.');