authenticate(); } catch (TokenExpiredException $e) { return response()->json(['error' => 'Token has expired'], 401); } catch (TokenInvalidException $e) { return response()->json(['error' => 'Token is invalid'], 401); } catch (JWTException $e) { return response()->json(['error' => 'Token is missing or invalid'], 401); } catch (TokenExpiredException $e) { // Invalidate the old token $token = JWTAuth::getToken(); JWTAuth::invalidate($token); // Return an error response with instructions for obtaining a new token return response()->json([ 'error' => 'Token has expired', 'message' => 'Please obtain a new token from the authentication endpoint.' ], 401); } // // Check if the user has the required role or permissions // if (!$user->hasRole('admin') && !$user->hasPermission('access_admin_panel')) { // return response()->json(['error' => 'Unauthorized'], 403); // } return $next($request); } }