From c80baf4807c2285a206eb62feb0a398993239f65 Mon Sep 17 00:00:00 2001 From: F4ilji Date: Thu, 2 Jul 2026 13:38:03 +0500 Subject: [PATCH] fix: return JSON 401 for unauthenticated API requests --- .../UI/WEB/Middleware/EnsureDashboardAuthenticated.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Containers/Dashboard/UI/WEB/Middleware/EnsureDashboardAuthenticated.php b/app/Containers/Dashboard/UI/WEB/Middleware/EnsureDashboardAuthenticated.php index 5e9db34..0017253 100644 --- a/app/Containers/Dashboard/UI/WEB/Middleware/EnsureDashboardAuthenticated.php +++ b/app/Containers/Dashboard/UI/WEB/Middleware/EnsureDashboardAuthenticated.php @@ -15,6 +15,9 @@ class EnsureDashboardAuthenticated public function handle(Request $request, Closure $next): Response { if (!Auth::check()) { + if ($request->expectsJson() || $request->is('api/*')) { + return response()->json(['error' => 'Unauthenticated'], 401); + } return redirect()->route('login'); }