From c09c6108af051c7f1683bf66162a5c31d46a81cb Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 25 Dec 2023 14:15:33 +0700 Subject: [PATCH] perbaikan request login API --- .../API/v1/AuthApi/LoginApiController.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/API/v1/AuthApi/LoginApiController.php b/app/Http/Controllers/API/v1/AuthApi/LoginApiController.php index d7be905..62afa8b 100644 --- a/app/Http/Controllers/API/v1/AuthApi/LoginApiController.php +++ b/app/Http/Controllers/API/v1/AuthApi/LoginApiController.php @@ -55,13 +55,23 @@ class LoginApiController extends Controller $user = auth()->guard('api')->user(); // Load roles for the user - // $user->load('roles'); + $user->load(['role' => function ($query) { + $query->select('id', 'name', 'deleted_at'); + }]); + + // Check if user is deleted + if ($user->deleted_at) { + auth()->guard('api')->logout(); + return response()->json([ + 'success' => false, + 'message' => 'Akun Anda telah dihapus. Tidak dapat login.' + ], 401); + } return ResponseFormatter::success([ 'token_type' => 'Bearer', 'user' => $user, - 'token' => $token - // 'roles' => $user->roles + 'token' => $token, ], 'Authentication successful'); } catch (\Exception $e) { return ResponseFormatter::error([