From 5cfabaebb322398052edad84c757f0f577ba23c3 Mon Sep 17 00:00:00 2001
From: Alexander <alexandergaruba96@gmail.com>
Date: Tue, 6 Feb 2024 10:06:44 +0100
Subject: [PATCH] Add JSON response for blocked account login*** ***Add JSON
 response for blocked account login in LogsOutBannedUser middleware

---
 src/Http/Middleware/ForbidBannedUser.php  | 4 ++++
 src/Http/Middleware/LogsOutBannedUser.php | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/src/Http/Middleware/ForbidBannedUser.php b/src/Http/Middleware/ForbidBannedUser.php
index a19b98a..e8e9510 100644
--- a/src/Http/Middleware/ForbidBannedUser.php
+++ b/src/Http/Middleware/ForbidBannedUser.php
@@ -53,6 +53,10 @@ public function handle($request, Closure $next)
                 'login' => 'This account is blocked.',
             ];
 
+            if ($request->expectsJson()) {
+                abort(403, $errors['login']);
+            }
+
             $responseCode = $request->header('X-Inertia') ? 303 : 302;
             if ($redirectUrl === null) {
                 return redirect()->back($responseCode)->withInput()->withErrors($errors);
diff --git a/src/Http/Middleware/LogsOutBannedUser.php b/src/Http/Middleware/LogsOutBannedUser.php
index 3d48f66..a63594c 100644
--- a/src/Http/Middleware/LogsOutBannedUser.php
+++ b/src/Http/Middleware/LogsOutBannedUser.php
@@ -59,6 +59,10 @@ public function handle($request, Closure $next)
                 'login' => 'This account is blocked.',
             ];
 
+            if ($request->expectsJson()) {
+                abort(403, $errors['login']);
+            }
+
             $responseCode = $request->header('X-Inertia') ? 303 : 302;
             if ($redirectUrl === null) {
                 return redirect()->back($responseCode)->withInput()->withErrors($errors);