Ensure tokens are found in the database using the expected logic

This commit is contained in:
DaneEveritt 2022-05-22 16:05:58 -04:00
parent e9c633fd03
commit f7fc67344e
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 39 additions and 25 deletions

View file

@ -19,19 +19,19 @@ class AccountController extends ClientApiController
private $updateService;
/**
* @var \Illuminate\Auth\SessionGuard
* @var \Illuminate\Auth\AuthManager
*/
private $sessionGuard;
private $manager;
/**
* AccountController constructor.
*/
public function __construct(AuthManager $sessionGuard, UserUpdateService $updateService)
public function __construct(AuthManager $manager, UserUpdateService $updateService)
{
parent::__construct();
$this->updateService = $updateService;
$this->sessionGuard = $sessionGuard;
$this->manager = $manager;
}
public function index(Request $request): array
@ -64,13 +64,17 @@ class AccountController extends ClientApiController
{
$user = $this->updateService->handle($request->user(), $request->validated());
$guard = $this->manager->guard();
// If you do not update the user in the session you'll end up working with a
// cached copy of the user that does not include the updated password. Do this
// to correctly store the new user details in the guard and allow the logout
// other devices functionality to work.
$this->sessionGuard->setUser($user);
$guard->setUser($user);
$this->sessionGuard->logoutOtherDevices($request->input('password'));
// This method doesn't exist in the stateless Sanctum world.
if (method_exists($guard, 'logoutOtherDevices')) {
$guard->logoutOtherDevices($request->input('password'));
}
return new JsonResponse([], Response::HTTP_NO_CONTENT);
}