diff --git a/src/Config/Auth.php b/src/Config/Auth.php index 1c7d57902..ee06c2c65 100644 --- a/src/Config/Auth.php +++ b/src/Config/Auth.php @@ -409,7 +409,8 @@ class Auth extends BaseConfig */ public function loginRedirect(): string { - $url = setting('Auth.redirects')['login']; + $session = session(); + $url = $session->getTempdata('beforeLogginUrl') ?? setting('Auth.redirects')['login']; return $this->getUrl($url); } diff --git a/src/Filters/SessionAuth.php b/src/Filters/SessionAuth.php index d95f89c07..afd0b3cba 100644 --- a/src/Filters/SessionAuth.php +++ b/src/Filters/SessionAuth.php @@ -75,6 +75,11 @@ public function before(RequestInterface $request, $arguments = null) ->with('error', $authenticator->getPendingMessage()); } + if (! url_is('login')) { + $session = session(); + $session->setTempdata('beforeLogginUrl', current_url(), 300); + } + return redirect()->route('login'); } diff --git a/tests/Authentication/Filters/SessionFilterTest.php b/tests/Authentication/Filters/SessionFilterTest.php index 759a88535..41d44621b 100644 --- a/tests/Authentication/Filters/SessionFilterTest.php +++ b/tests/Authentication/Filters/SessionFilterTest.php @@ -83,4 +83,12 @@ public function testBlocksInactiveUsers(): void setting('Auth.actions', ['register' => null]); } + + public function testStoreRedirectsToEntraceUrlIntoSession(): void + { + $result = $this->call('get', 'protected-route'); + $result->assertRedirectTo('/login'); + $this->assertNotEmpty($_SESSION['beforeLogginUrl']); + $this->assertSame(site_url('protected-route'), $_SESSION['beforeLogginUrl']); + } }