diff --git a/src/Actions/RedirectIfTwoFactorAuthenticatable.php b/src/Actions/RedirectIfTwoFactorAuthenticatable.php index 4e9c0ec7..2cf32470 100644 --- a/src/Actions/RedirectIfTwoFactorAuthenticatable.php +++ b/src/Actions/RedirectIfTwoFactorAuthenticatable.php @@ -6,6 +6,7 @@ use Illuminate\Contracts\Auth\StatefulGuard; use Illuminate\Support\Facades\Hash; use Illuminate\Validation\ValidationException; +use Laravel\Fortify\Events\TwoFactorAuthenticationChallenged; use Laravel\Fortify\Fortify; use Laravel\Fortify\LoginRateLimiter; use Laravel\Fortify\TwoFactorAuthenticatable; @@ -133,6 +134,8 @@ protected function twoFactorChallengeResponse($request, $user) 'login.remember' => $request->filled('remember'), ]); + TwoFactorAuthenticationChallenged::dispatch($user); + return $request->wantsJson() ? response()->json(['two_factor' => true]) : redirect()->route('two-factor.login'); diff --git a/src/Events/TwoFactorAuthenticationChallenged.php b/src/Events/TwoFactorAuthenticationChallenged.php new file mode 100644 index 00000000..3694f565 --- /dev/null +++ b/src/Events/TwoFactorAuthenticationChallenged.php @@ -0,0 +1,8 @@ +set('auth.providers.users.model', TestTwoFactorAuthenticationSessionUser::class); $this->loadLaravelMigrations(['--database' => 'testbench']); @@ -69,6 +73,8 @@ public function test_user_is_redirected_to_challenge_when_using_two_factor_authe ]); $response->assertRedirect('/two-factor-challenge'); + + Event::assertDispatched(TwoFactorAuthenticationChallenged::class); } public function test_user_can_authenticate_when_two_factor_challenge_is_disabled()