|
|
@ -55,13 +55,23 @@ class LoginApiController extends Controller |
|
|
|
$user = auth()->guard('api')->user(); |
|
|
|
$user = auth()->guard('api')->user(); |
|
|
|
|
|
|
|
|
|
|
|
// Load roles for the 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([ |
|
|
|
return ResponseFormatter::success([ |
|
|
|
'token_type' => 'Bearer', |
|
|
|
'token_type' => 'Bearer', |
|
|
|
'user' => $user, |
|
|
|
'user' => $user, |
|
|
|
'token' => $token |
|
|
|
'token' => $token, |
|
|
|
// 'roles' => $user->roles |
|
|
|
|
|
|
|
], 'Authentication successful'); |
|
|
|
], 'Authentication successful'); |
|
|
|
} catch (\Exception $e) { |
|
|
|
} catch (\Exception $e) { |
|
|
|
return ResponseFormatter::error([ |
|
|
|
return ResponseFormatter::error([ |
|
|
|