Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Allow to customise redirect URL in AuthenticateSession Middleware #46752

Merged
merged 2 commits into from Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Illuminate/Session/Middleware/AuthenticateSession.php
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Auth\Factory as AuthFactory;
use Illuminate\Contracts\Session\Middleware\AuthenticatesSessions;
use Illuminate\Http\Request;

class AuthenticateSession implements AuthenticatesSessions
{
Expand Down Expand Up @@ -94,7 +95,9 @@ protected function logout($request)

$request->session()->flush();

throw new AuthenticationException('Unauthenticated.', [$this->auth->getDefaultDriver()]);
throw new AuthenticationException(
'Unauthenticated.', [$this->auth->getDefaultDriver()], $this->redirectTo($request)
);
}

/**
Expand All @@ -106,4 +109,15 @@ protected function guard()
{
return $this->auth;
}

/**
* Get the path the user should be redirected to when their session is not autheneticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo(Request $request)
{
//
}
}