Okay, so it seems that everything works fine after I restarted my machine....
The guest middleware RedirectIfAuthenticated is not working for me correctly with InertiaJs
Hello,
I am currently in the process of migrating to InertiaJs for our Laravel applications. I could not use Breeze. But I fired up a new Laravel Project and copy pasted the required Files over. Everything is working except the guest middleware. So currently authenticated Users can still visit the login and registration page. I am unsure how I can fix this. Any hints would be appreciated.
The Login:
public function store(LoginRequest $request)
{
$validated = $request->validated();
$securityKey = $validated['securityKey'];
if ($securityKey !== config('auth.BACKEND_SECURITY_KEY')) {
return redirect()->back()->withErrors(['error' => 'Invalid Login']);
}
$request->authenticate();
$request->session()->regenerate();
return redirect()->intended(config('wd.authentication.redirects.after_login'));
}
The middleware:
public function handle(Request $request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
}
return $next($request);
}
I noticed that the StartSession middleware runs currently after the RedirectIfAuthenticated. I think that might be the issue because this Auth::guard($guard)->check() currently returns null.
Please or to participate in this conversation.