Level 122
possibly return a 400 error ( bad request) or a redirection
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
how to handle the RedirectIfAuthenticated middleware in API requests
someone send a request to login endpoint with bearer token and after that user redirected to the dashboard
what is the appropriate response I should respond to?
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
if ($request->wantsJson()) {
return response()->json(); // ?
}
return redirect('/');
}
return $next($request);
}
possibly return a 400 error ( bad request) or a redirection
Please or to participate in this conversation.