Skip to content

Commit 67d7743

Browse files
committed
adjust redirect
1 parent 04ab43c commit 67d7743

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/Http/Controllers/TwoFactorAuthenticatedSessionController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Laravel\Fortify\Http\Controllers;
44

55
use Illuminate\Contracts\Auth\StatefulGuard;
6+
use Illuminate\Http\Exceptions\HttpResponseException;
67
use Illuminate\Routing\Controller;
78
use Laravel\Fortify\Contracts\FailedTwoFactorLoginResponse;
89
use Laravel\Fortify\Contracts\TwoFactorChallengeViewResponse;
@@ -33,12 +34,12 @@ public function __construct(StatefulGuard $guard)
3334
* Show the two factor authentication challenge view.
3435
*
3536
* @param \Laravel\Fortify\Http\Requests\TwoFactorLoginRequest $request
36-
* @return \Laravel\Fortify\Contracts\TwoFactorChallengeViewResponse|\Illuminate\Http\RedirectResponse
37+
* @return \Laravel\Fortify\Contracts\TwoFactorChallengeViewResponse
3738
*/
38-
public function create(TwoFactorLoginRequest $request)
39+
public function create(TwoFactorLoginRequest $request): TwoFactorChallengeViewResponse
3940
{
4041
if (! $request->hasChallengedUser()) {
41-
return redirect()->route('login');
42+
throw new HttpResponseException(redirect()->route('login'));
4243
}
4344

4445
return app(TwoFactorChallengeViewResponse::class);

src/Http/Requests/TwoFactorLoginRequest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ public function validRecoveryCode()
7575
});
7676
}
7777

78+
/**
79+
* Determine if there is a challenged user in the current session.
80+
*
81+
* @return bool
82+
*/
83+
public function hasChallengedUser()
84+
{
85+
try {
86+
$user = $this->challengedUser();
87+
} catch (HttpResponseException $e) {
88+
return false;
89+
}
90+
91+
return $user !== null;
92+
}
93+
7894
/**
7995
* Get the user that is attempting the two factor challenge.
8096
*
@@ -98,22 +114,6 @@ public function challengedUser()
98114
return $this->challengedUser = $user;
99115
}
100116

101-
/**
102-
* Determine if there's a challenged user in the current session.
103-
*
104-
* @return bool
105-
*/
106-
public function hasChallengedUser()
107-
{
108-
try {
109-
$user = $this->challengedUser();
110-
} catch (HttpResponseException $e) {
111-
return false;
112-
}
113-
114-
return $user !== null;
115-
}
116-
117117
/**
118118
* Determine if the user wanted to be remembered after login.
119119
*

0 commit comments

Comments
 (0)