codezero-be / laravel-stagefront

⭐️ Quickly add some password protection to a staging site.
MIT License
16 stars 5 forks source link

Consistent 404s after login on Laravel 9 #8

Open joereynolds opened 1 year ago

joereynolds commented 1 year ago

Hello!

I saw issue #4 and I thought it might solve my problem but unfortunately it doesn't help.

The problem

After installing the project via composer, I then add the middleware:

diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php
index 9fb429db..2a6c3058 100644
--- a/app/Http/Kernel.php
+++ b/app/Http/Kernel.php
@@ -35,6 +35,7 @@ class Kernel extends HttpKernel
             \App\Http\Middleware\EncryptCookies::class,
             \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
             \Illuminate\Session\Middleware\StartSession::class,
+            \CodeZero\StageFront\Middleware\RedirectIfStageFrontIsEnabled::class,
             // \Illuminate\Session\Middleware\AuthenticateSession::class,
             \Illuminate\View\Middleware\ShareErrorsFromSession::class,
             \App\Http\Middleware\VerifyCsrfToken::class,

(Note this is the only place to add it, there is no $middlewarePriority for Laravel 9 from what I can tell).

After this, I add these .env values

STAGEFRONT_ENABLED=TRUE
STAGEFRONT_LOGIN=test
STAGEFRONT_PASSWORD=password

The stagefront page loads successfully but any successful or unsuccessful logins get immediately redirected to a 404. I have cleared and populated the cache with route:cache and ran into the same problems.

Thanks, and I hope you can help!

ivanvermeyen commented 1 year ago

I believe $middlewarePriority is not in the kernel by default. You have to copy it from the base class.

joereynolds commented 1 year ago

After copying Laravel's $middlewarePriority over (and doing a ./artisan route:cache), it's still giving the same error unfortunately :(

diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php
index 9fb429db..494a7dd2 100644
--- a/app/Http/Kernel.php
+++ b/app/Http/Kernel.php
@@ -25,6 +25,20 @@ class Kernel extends HttpKernel
         \App\Http\Middleware\FixNewRelicUnknownTransactionMiddleware::class,
     ];

+    protected $middlewarePriority = [
+        \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
+        \Illuminate\Cookie\Middleware\EncryptCookies::class,
+        \Illuminate\Session\Middleware\StartSession::class,
+        \CodeZero\StageFront\Middleware\RedirectIfStageFrontIsEnabled::class,
+        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
+        \Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests::class,
+        \Illuminate\Routing\Middleware\ThrottleRequests::class,
+        \Illuminate\Routing\Middleware\ThrottleRequestsWithRedis::class,
+        \Illuminate\Contracts\Session\Middleware\AuthenticatesSessions::class,
+        \Illuminate\Routing\Middleware\SubstituteBindings::class,
+        \Illuminate\Auth\Middleware\Authorize::class,
+    ];
+
     /**
      * The application's route middleware groups.
      *
ivanvermeyen commented 1 year ago

Can you track where it is redirecting to?

On success it should redirect to the "intended" route or "/". On error it should redirect back with errors as per default validation behavior.

https://github.com/codezero-be/laravel-stagefront/blob/master/src/Controllers/StageFrontController.php

joereynolds commented 1 year ago

Yes, so the login is at:

https://my-domain.local.test.io/myprefixed/path/stagefront/

And on either failure or success it goes to:

https://my-domain.local.test.io/myprefixed/path/stagefront/stagefront/

No validation errors come through. I'll try and debug further when I get the chance