Skip to content

Commit 152da97

Browse files
committed
Disable login and signup on master (auth only on dev branch)
Made-with: Cursor
1 parent 2a3ca5d commit 152da97

14 files changed

Lines changed: 101 additions & 12 deletions
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
use Symfony\Component\HttpFoundation\Response;
8+
9+
class EnsureAuthPublic
10+
{
11+
/**
12+
* Paths that are disabled when auth is not public (login/signup disabled).
13+
*/
14+
protected array $authPaths = [
15+
'login',
16+
'register',
17+
'forgot-password',
18+
'reset-password',
19+
'two-factor-challenge',
20+
'email/verify',
21+
];
22+
23+
public function handle(Request $request, Closure $next): Response
24+
{
25+
if (config('services.auth_public', true)) {
26+
return $next($request);
27+
}
28+
29+
$path = trim($request->path(), '/');
30+
31+
foreach ($this->authPaths as $authPath) {
32+
if ($path === $authPath || str_starts_with($path, $authPath.'/')) {
33+
return redirect()->route('home')
34+
->with('status', 'Login and sign up are not available.');
35+
}
36+
}
37+
38+
return $next($request);
39+
}
40+
}

bootstrap/app.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Http\Middleware\EnsureAuthPublic;
34
use App\Http\Middleware\HandleAppearance;
45
use App\Http\Middleware\HandleInertiaRequests;
56
use Illuminate\Foundation\Application;
@@ -17,6 +18,7 @@
1718
$middleware->encryptCookies(except: ['appearance', 'sidebar_state']);
1819

1920
$middleware->web(append: [
21+
EnsureAuthPublic::class,
2022
HandleAppearance::class,
2123
HandleInertiaRequests::class,
2224
AddLinkHeadersForPreloadedAssets::class,

config/services.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,16 @@
3636
],
3737
],
3838

39+
/*
40+
|--------------------------------------------------------------------------
41+
| Auth public (login / signup)
42+
|--------------------------------------------------------------------------
43+
|
44+
| When true, /login and /register are available. When false, they redirect
45+
| to home. Default is false on master (auth disabled); set AUTH_PUBLIC=true
46+
| or use the dev branch for login/signup.
47+
|
48+
*/
49+
'auth_public' => env('AUTH_PUBLIC', false),
50+
3951
];

routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
Route::get('/', function () {
2222
return Inertia::render('Welcome', [
23-
'canRegister' => Features::enabled(Features::registration()),
23+
'canRegister' => config('services.auth_public', true) && Features::enabled(Features::registration()),
2424
]);
2525
})->name('home');
2626

tests/Feature/Auth/AuthenticationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
use Illuminate\Support\Facades\RateLimiter;
55
use Laravel\Fortify\Features;
66

7+
beforeEach(function () {
8+
if (! auth_public()) {
9+
$this->markTestSkipped('Login/signup is disabled on this branch.');
10+
}
11+
});
12+
713
test('login screen can be rendered', function () {
814
$response = $this->get(route('login'));
915

tests/Feature/Auth/PasswordConfirmationTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
use App\Models\User;
44
use Inertia\Testing\AssertableInertia as Assert;
55

6+
beforeEach(function () {
7+
if (! auth_public()) {
8+
$this->markTestSkipped('Login/signup is disabled on this branch.');
9+
}
10+
});
11+
612
test('confirm password screen can be rendered', function () {
713
$user = User::factory()->create();
814

@@ -18,5 +24,5 @@
1824
test('password confirmation requires authentication', function () {
1925
$response = $this->get(route('password.confirm'));
2026

21-
$response->assertRedirect(route('login'));
27+
$response->assertRedirect(guest_redirect_target());
2228
});

tests/Feature/Auth/PasswordResetTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
use Illuminate\Auth\Notifications\ResetPassword;
55
use Illuminate\Support\Facades\Notification;
66

7+
beforeEach(function () {
8+
if (! auth_public()) {
9+
$this->markTestSkipped('Login/signup is disabled on this branch.');
10+
}
11+
});
12+
713
test('reset password link screen can be rendered', function () {
814
$response = $this->get(route('password.request'));
915

tests/Feature/Auth/RegistrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php
22

3+
beforeEach(function () {
4+
if (! auth_public()) {
5+
$this->markTestSkipped('Login/signup is disabled on this branch.');
6+
}
7+
});
8+
39
test('registration screen can be rendered', function () {
410
$response = $this->get(route('register'));
511

tests/Feature/Auth/TwoFactorChallengeTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
use Inertia\Testing\AssertableInertia as Assert;
55
use Laravel\Fortify\Features;
66

7+
beforeEach(function () {
8+
if (! auth_public()) {
9+
$this->markTestSkipped('Login/signup is disabled on this branch.');
10+
}
11+
});
12+
713
test('two factor challenge redirects to login when not authenticated', function () {
814
if (! Features::canManageTwoFactorAuthentication()) {
915
$this->markTestSkipped('Two-factor authentication is not enabled.');

tests/Feature/ChangelogEntryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use function Pest\Laravel\patch;
1010
use function Pest\Laravel\delete;
1111

12-
it('redirects guests from changelog index to login', function () {
13-
get(route('changelog.index'))->assertRedirect(route('login'));
12+
it('redirects guests from changelog index to login or home when auth disabled', function () {
13+
get(route('changelog.index'))->assertRedirect(guest_redirect_target());
1414
});
1515

1616
it('lists only the authenticated users changelog entries', function () {

0 commit comments

Comments
 (0)