Skip to content

Commit e8582a8

Browse files
committed
Linting Changes
1 parent 46e5b6c commit e8582a8

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

app/Providers/FortifyServiceProvider.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
use Illuminate\Cache\RateLimiting\Limit;
66
use Illuminate\Http\Request;
77
use Illuminate\Support\Facades\RateLimiter;
8+
use Illuminate\Support\Facades\Route;
89
use Illuminate\Support\ServiceProvider;
910
use Illuminate\Support\Str;
10-
use Laravel\Fortify\Actions\RedirectIfTwoFactorAuthenticatable;
11+
use Inertia\Inertia;
1112
use Laravel\Fortify\Fortify;
1213

1314
class FortifyServiceProvider extends ServiceProvider
@@ -25,7 +26,12 @@ public function register(): void
2526
*/
2627
public function boot(): void
2728
{
28-
Fortify::redirectUserForTwoFactorAuthenticationUsing(RedirectIfTwoFactorAuthenticatable::class);
29+
Fortify::loginView(fn (Request $request) => Inertia::render('auth/Login', [
30+
'canResetPassword' => Route::has('password.request'),
31+
'status' => $request->session()->get('status'),
32+
]));
33+
Fortify::twoFactorChallengeView(fn () => Inertia::render('auth/TwoFactorChallenge'));
34+
Fortify::confirmPasswordView(fn () => Inertia::render('auth/ConfirmPassword'));
2935

3036
RateLimiter::for('two-factor', function (Request $request) {
3137
return Limit::perMinute(5)->by($request->session()->get('login.id'));

config/fortify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
|
131131
*/
132132

133-
'views' => false,
133+
'views' => true,
134134

135135
/*
136136
|--------------------------------------------------------------------------

routes/auth.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,9 @@
66
use App\Http\Controllers\Auth\PasswordResetLinkController;
77
use App\Http\Controllers\Auth\RegisteredUserController;
88
use App\Http\Controllers\Auth\VerifyEmailController;
9-
use Illuminate\Http\Request;
109
use Illuminate\Support\Facades\Route;
11-
use Inertia\Inertia;
1210

1311
Route::middleware('guest')->group(function () {
14-
Route::get('login', fn (Request $request) => Inertia::render('auth/Login', [
15-
'canResetPassword' => Route::has('password.request'),
16-
'status' => $request->session()->get('status'),
17-
]))->name('login');
18-
1912
Route::get('register', [RegisteredUserController::class, 'create'])
2013
->name('register');
2114

@@ -46,10 +39,4 @@
4639
Route::post('email/verification-notification', [EmailVerificationNotificationController::class, 'store'])
4740
->middleware('throttle:6,1')
4841
->name('verification.send');
49-
50-
Route::get('user/confirm-password', fn () => Inertia::render('auth/ConfirmPassword'))
51-
->name('password.confirm');
52-
53-
Route::get('two-factor-challenge', fn () => Inertia::render('auth/TwoFactorChallenge'))
54-
->name('two-factor.login');
5542
});

tests/Feature/Auth/AuthenticationTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\User;
66
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Illuminate\Support\Facades\RateLimiter;
78
use Laravel\Fortify\Features;
89
use Tests\TestCase;
910

@@ -81,4 +82,18 @@ public function test_users_can_logout()
8182
$this->assertGuest();
8283
$response->assertRedirect(route('home'));
8384
}
85+
86+
public function test_users_are_rate_limited()
87+
{
88+
$user = User::factory()->create();
89+
90+
RateLimiter::increment(md5('login'.implode('|', [$user->email, '127.0.0.1'])), amount: 5);
91+
92+
$response = $this->post(route('login.store'), [
93+
'email' => $user->email,
94+
'password' => 'wrong-password',
95+
]);
96+
97+
$response->assertTooManyRequests();
98+
}
8499
}

tests/Feature/Auth/TwoFactorChallengeTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\User;
66
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Inertia\Testing\AssertableInertia;
78
use Laravel\Fortify\Features;
89
use Tests\TestCase;
910

@@ -35,17 +36,15 @@ public function test_two_factor_challenge_can_be_rendered(): void
3536

3637
$user = User::factory()->create();
3738

38-
$user->forceFill([
39-
'two_factor_secret' => encrypt('test-secret'),
40-
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
41-
'two_factor_confirmed_at' => now(),
42-
])->save();
43-
44-
$response = $this->post(route('login'), [
39+
$this->post(route('login'), [
4540
'email' => $user->email,
4641
'password' => 'password',
4742
]);
4843

49-
$response->assertRedirect(route('two-factor.login'));
44+
$this->get(route('two-factor.login'))
45+
->assertOk()
46+
->assertInertia(fn (AssertableInertia $page) => $page
47+
->component('auth/TwoFactorChallenge')
48+
);
5049
}
5150
}

0 commit comments

Comments
 (0)