Hi i am currently having a problem about JWT Exception JSON Message. The problem is when i checkIn but my token is expired and i received this
"message": "Token has expired",
"exception": "Tymon\\JWTAuth\\Exceptions\\TokenExpiredException",
"file": "C:\\Users\\Snowfox1991\\Desktop\\Capstone project\\back-end\\back-end\\vendor\\tymon\\jwt-auth\\src\\Claims\\Expiration.php",
"line": 31,
But when i write the getAuthUser() in APIController, i use try catch this one
public function getAuthUser(Request $request)
{
$this->validate($request, [
'token' => 'required'
]);
$user = JWTAuth::authenticate($request->token);
try {
if (!$user = JWTAuth::parseToken()->authenticate()) {
return response()->json(['user_not_found'], 404);
}
} catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
response()->json([
'status' => 'error',
'message' => 'Token has expired'
], $e->getStatusCode()
} catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
response()->json([
'status' => 'error',
'message' => 'Token is invalid'
], $e->getStatusCode()
} catch (Tymon\JWTAuth\Exceptions\JWTException $e) {
response()->json([
'status' => 'error',
'message' => 'Token is absent'
], $e->getStatusCode()
// }
return response()->json(['user' => $user]);
}
And it still return the same as the original without the json format. Can i ask how to improve this exception using json format without handling the error like this. Thank you