fix(middlewares): handle guest and auth redirects correctly

Ensure that both guest and authenticated user redirects are processed properly.
This commit is contained in:
Jérémy Munsch 2026-11-14 23:10:11 +01:00
parent 341a66a2d1
commit bd314a4575
No known key found for this signature in database
GPG key ID: 2AAECDA6B7330F91

View file

@ -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;
}
}
}
}