Skip to content

Commit 8f6b429

Browse files
author
Gareth Redfern
committed
send json if expected RedirectIfAuthenticated
1 parent e18ab1c commit 8f6b429

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

app/Http/Middleware/RedirectIfAuthenticated.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public function handle(Request $request, Closure $next, ...$guards)
2323

2424
foreach ($guards as $guard) {
2525
if (Auth::guard($guard)->check()) {
26-
return redirect(RouteServiceProvider::HOME);
26+
if ($request->expectsJson()) {
27+
return response()->json(['error' => 'Already authenticated.'], 400);
28+
}
29+
return redirect(RouteServiceProvider::HOME);
2730
}
2831
}
2932

0 commit comments

Comments
 (0)