from rest_framework_simplejwt.exceptions import InvalidToken, TokenError from rest_framework_simplejwt.tokens import AccessToken from core.auth import JWTStatelessUserAuthentication as OriginalAuthentication class VerifiedJWTStatelessUserAuthentication(OriginalAuthentication): def get_validated_token(self, raw_token): try: AccessToken(raw_token, verify=True) except TokenError: raise InvalidToken("Invalid or expired access token") from None return super().get_validated_token(raw_token)