Open
Description
Fortify Version
1.25.3
Laravel Version
10.48.27
PHP Version
8.1
Database Driver & Version
No response
Description
The TwoFactorAuthenticatedSessionController dispatches a RecoveryCodeReplaced event
but User::replaceRecoveryCode already dispatches the exact same event
fortify/src/TwoFactorAuthenticatable.php
Lines 47 to 57 in 1711276
I’m not sure where it would make the most sense to keep the dispatch, but I think it’s reasonable to avoid triggering it twice.
Steps To Reproduce
public function test_two_factor_challenge_with_recovery_code_dispatches_RecoveryCodeReplaced_twice()
{
Event::fake();
$user = UserWithTwoFactor::forceCreate([
'name' => 'Taylor Otwell',
'email' => '[email protected]',
'password' => bcrypt('secret'),
'two_factor_recovery_codes' => encrypt(json_encode(['invalid-code', 'valid-code'])),
]);
$response = $this->withSession([
'login.id' => $user->id,
'login.remember' => false,
])->withoutExceptionHandling()->post('/two-factor-challenge', [
'recovery_code' => 'valid-code',
]);
Event::assertDispatchedTimes(RecoveryCodeReplaced::class, 2);
}