From bd314a45758d09ebcb7bedbd8ea17f1aa6d0454b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Sat, 14 Nov 2026 23:10:11 +0100 Subject: [PATCH] fix(middlewares): handle guest and auth redirects correctly Ensure that both guest and authenticated user redirects are processed properly. --- bootstrap/middlewares.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bootstrap/middlewares.php b/bootstrap/middlewares.php index c5dc5e15..6f1414b2 100644 --- a/bootstrap/middlewares.php +++ b/bootstrap/middlewares.php @@ -44,11 +44,17 @@ $redirectUsers = function (Request $request) { 'backend' => route('bo.dashboard'), 'frontend' => route('fo.pages.home'), ]; - foreach ($request->route()->gatherMiddleware() as $middleware) { - if (\is_string($middleware) && str_contains($middleware, 'auth:')) { - $route = $logins[str_replace('auth:', '', $middleware)] ?? null; - if ($route) { - return $route; + foreach ($request->route()?->gatherMiddleware() ?? [] as $middleware) { + if (! \is_string($middleware)) { + continue; + } + + foreach (['auth:', 'guest:'] as $prefix) { + if (str_starts_with($middleware, $prefix)) { + $route = $logins[substr($middleware, strlen($prefix))] ?? null; + if ($route) { + return $route; + } } } }