File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load diff This file was deleted.
Original file line number Diff line number Diff line change 22
33declare (strict_types=1 );
44
5- use App \Http \Middleware \Authenticate ;
65use App \Providers \AppServiceProvider ;
76use Illuminate \Foundation \Application ;
87use Illuminate \Foundation \Configuration \Exceptions ;
98use Illuminate \Foundation \Configuration \Middleware ;
9+ use Illuminate \Http \Request ;
1010use KgBot \LaravelLocalization \LaravelLocalizationServiceProvider ;
1111
1212return Application::configure (basePath: dirname (__DIR__ ))
2323 ->withMiddleware (function (Middleware $ middleware ) {
2424 $ middleware ->redirectUsersTo (AppServiceProvider::HOME );
2525
26- $ middleware ->throttleApi ();
26+ $ middleware ->redirectGuestsTo (
27+ fn (Request $ request ) => $ request ->expectsJson () ? null : route_wlocale ('login ' ),
28+ );
2729
28- $ middleware ->alias ([
29- 'auth ' => Authenticate::class,
30- ]);
30+ $ middleware ->throttleApi ();
3131 })
3232 ->withExceptions (function (Exceptions $ exceptions ) {
3333 //
Original file line number Diff line number Diff line change 99uses (TestCase::class);
1010uses (RefreshDatabase::class);
1111
12+ test ('guests are redirected to the locale-prefixed login page ' , function () {
13+ $ this ->get ('/en/profile ' )->assertRedirect ('/en/login ' );
14+ });
15+
16+ test ('guest json requests receive 401 instead of a redirect ' , function () {
17+ $ this ->getJson ('/en/profile ' )->assertUnauthorized ();
18+ });
19+
1220test ('user can log in ' , function () {
1321 $ user = User::factory ()->create ();
1422
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Illuminate \Foundation \Testing \RefreshDatabase ;
6+ use Tests \NovaTestCase ;
7+
8+ uses (NovaTestCase::class);
9+ uses (RefreshDatabase::class);
10+
11+ test ('guest json requests to nova api receive 401 instead of a url generation error ' , function () {
12+ $ this ->getJson ('/nova-api/users ' )->assertUnauthorized ();
13+ });
14+
15+ test ('guest non-json requests to nova api do not throw a url generation error ' , function () {
16+ // Regression: the framework's default guest redirect calls route('login')
17+ // without the required {locale} parameter, causing a 500 in production.
18+ $ this ->get ('/nova-api/users ' )->assertUnauthorized ();
19+ });
20+
21+ test ('guests requesting nova pages are redirected to the nova login page ' , function () {
22+ $ this ->get ('/nova ' )->assertRedirect ('/nova/login ' );
23+ });
You can’t perform that action at this time.
0 commit comments