Skip to content

Commit

Permalink
[10.x] Remove session on authenticatable deletion v2 (#47141)
Browse files Browse the repository at this point in the history
* Clear session from storage if no recaller can be found

* Update SessionGuard.php

* Fixed tests to expect new behavior.

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
Boorinio and taylorotwell committed May 22, 2023
1 parent fa4e0f1 commit 8fe2f65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Auth/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public function user()
}
}

if (is_null($this->user)) {
$this->clearUserDataFromStorage();
}

return $this->user;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/Auth/AuthGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ public function testAuthenticateThrowsWhenUserIsNull()
$this->expectExceptionMessage('Unauthenticated.');

$guard = $this->getGuard();
$guard->setCookieJar($cookies = m::mock(CookieJar::class));
$cookies->shouldReceive('unqueue')->once();
$guard->getSession()->shouldReceive('remove')->once();
$guard->getSession()->shouldReceive('get')->once()->andReturn(null);

$guard->authenticate();
Expand Down Expand Up @@ -313,6 +316,9 @@ public function testUserMethodReturnsCachedUser()
public function testNullIsReturnedForUserIfNoUserFound()
{
$mock = $this->getGuard();
$mock->setCookieJar($cookies = m::mock(CookieJar::class));
$cookies->shouldReceive('unqueue')->once();
$mock->getSession()->shouldReceive('remove')->once();
$mock->getSession()->shouldReceive('get')->once()->andReturn(null);
$this->assertNull($mock->user());
}
Expand Down

0 comments on commit 8fe2f65

Please sign in to comment.