Skip to content

Commit 95a74d2

Browse files
[10.x] Allow to customise redirect URL in AuthenticateSession Middleware (#46752)
* feat: allow to customize redirect url in AuthenticateSession Middleware * Update AuthenticateSession.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 3b66c4d commit 95a74d2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Illuminate/Session/Middleware/AuthenticateSession.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Auth\AuthenticationException;
77
use Illuminate\Contracts\Auth\Factory as AuthFactory;
88
use Illuminate\Contracts\Session\Middleware\AuthenticatesSessions;
9+
use Illuminate\Http\Request;
910

1011
class AuthenticateSession implements AuthenticatesSessions
1112
{
@@ -94,7 +95,9 @@ protected function logout($request)
9495

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

97-
throw new AuthenticationException('Unauthenticated.', [$this->auth->getDefaultDriver()]);
98+
throw new AuthenticationException(
99+
'Unauthenticated.', [$this->auth->getDefaultDriver()], $this->redirectTo($request)
100+
);
98101
}
99102

100103
/**
@@ -106,4 +109,15 @@ protected function guard()
106109
{
107110
return $this->auth;
108111
}
112+
113+
/**
114+
* Get the path the user should be redirected to when their session is not autheneticated.
115+
*
116+
* @param \Illuminate\Http\Request $request
117+
* @return string|null
118+
*/
119+
protected function redirectTo(Request $request)
120+
{
121+
//
122+
}
109123
}

0 commit comments

Comments
 (0)