Background
I am using the ldaprecord-laravel package for LDAP authentication with Laravel 8. Users will be asked to authenticate to reach their intended page, and should be redirected to the intended page after authenticating. Basic authentication redirects correctly, but after I add my custom authentication guard a valid login will redirect to the home page of the application (RouteServiceProvider::HOME), which is the default behavior.
What I have tried
I tried editing App/Http/Middleware/RedirectIfAuthenticated.php to redirect to the intended page instead of the home page, I get the error ERR_TOO_MANY_REDIRECTS as it continually redirects from login -> intended -> login -> intended -> (...).
// App/Http/Middleware/RedirectIfAuthenticated.php
public function handle(Request $request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect()->intended(RouteServiceProvider::HOME);
// Original: return redirect(RouteServiceProvider::HOME);
}
}
return $next($request);
}
I have made no changes to Fortify's default routing behavior. Is there another way to redirect Fortify authentication when using a guard, or a missing configuration somewhere?