I have multiple authentication set up but I get this error sometimes, I need to find where there is a reference to the "login" route.
This is my code
//Middleware/Authenticate
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
if ($request->user('web')){
return route('admin_login_form');
} else if ($request->user('web_client')){
return url()->previous();
}
}
}
//Middleware/RedirectIfAuthenticated
public function handle(Request $request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
if ($guard === 'web'){
return redirect(RouteServiceProvider::ADMINHOME);
} else if ($guard === 'web_client'){
return url()->previous();
}
}
}
return $next($request);
}
//Providers/RouteServiceProvider
public const ADMINHOME = '/admin/home';
Then in all the Admin Auth Controllers that use $redirectTo
protected $redirectTo = RouteServiceProvider::ADMINHOME;
Then in all the Client Auth Controllers that use $redirectTo
public function redirectTo()
{
return url()->previous();
}
Here are my routes
Route::get('/', [App\Http\Controllers\HomeController::class, 'index'])->name('homepage');
Route::post('/login', [\App\Http\Controllers\ClientAuth\LoginController::class, 'login'])
->name('client_login');
Route::post('/logout', [\App\Http\Controllers\ClientAuth\LoginController::class, 'logout'])
->name('client_logout');
Route::middleware('auth:web_client')->group(function () {
Route::get('/home', [App\Http\Controllers\DashboardController::class, 'client_index'])
->name('client_dashboard');
});
Route::prefix('admin')->group(function () {
Route::get('/', [\App\Http\Controllers\AdminAuth\LoginController::class, 'showLoginForm'])
->name('admin_login_form');
Route::post('/login', [\App\Http\Controllers\AdminAuth\LoginController::class, 'login'])
->name('admin_login');
Route::post('/logout', [\App\Http\Controllers\AdminAuth\LoginController::class, 'logout'])
->name('admin_logout');
Route::middleware('auth:web')->group(function () {
Route::get('/home', [App\Http\Controllers\DashboardController::class, 'index'])
->name('admin_dashboard');
});
});
I'm not sure where else I have to setup the redirects to so it's not route('login').
What did I miss?