How to properly integrate middleware without ending up in a "TOO MANY REDIRECTS" issue
I'm validating the user->is_profile_complete column, then force redirect user to "Complete profile wizard" page, but ending up on too many redirects error
5 Replies
Show some code.
Panel:
->authMiddleware([
Authenticate::class,
EnsureEmailIsVerified::class,
EnsureProfileIsCompleted::class
]);
middleware
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if ($request->user()->hasRole(['Admin'])) return $next($request);
$account = $request->user()->account;
if ($account && (! $account->master_profile || ! $account->master_profile->isProfileCompleted())) {
return $request->expectsJson()
? abort(403, 'Some error message')
: redirect(route('filament.app.resources.users.edit-profile', $request->user()));
}
return $next($request);
}
@Dennis Koch added codes I usedYour Profile page is also Filament, right? So it's affected by the middelware too
Yes, it's a Filament too
Solution
So you need to exclude that route from your middleware