Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Config/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$url = $session->getTempdata('beforeLogginUrl') ?? setting('Auth.redirects')['login'];
$url = $session->getTempdata('beforeLoginUrl') ?? setting('Auth.redirects')['login'];


return $this->getUrl($url);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Filters/SessionAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$session->setTempdata('beforeLogginUrl', current_url(), 300);
$session->setTempdata('beforeLoginUrl', current_url(), 300);

}

return redirect()->route('login');
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Authentication/Filters/SessionFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Comment on lines +90 to +92
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All superglobals should be removed. So please use the Session class.

Suggested change
$result->assertRedirectTo('/login');
$this->assertNotEmpty($_SESSION['beforeLogginUrl']);
$this->assertSame(site_url('protected-route'), $_SESSION['beforeLogginUrl']);
$result->assertRedirectTo('/login');
$session = session();
$this->assertNotEmpty($session->get('beforeLogginUrl'));
$this->assertSame(site_url('protected-route'), $session->get('beforeLogginUrl'));

}
}