Update tokens.py

This commit is contained in:
David Bruno Vontor
2026-01-07 13:03:32 +01:00
parent c6ca9e2741
commit 7ebc83dd8c

View File

@@ -18,15 +18,22 @@ password_reset_token = PasswordResetTokenGenerator()
from rest_framework_simplejwt.authentication import JWTAuthentication from rest_framework_simplejwt.authentication import JWTAuthentication
from rest_framework_simplejwt.exceptions import InvalidToken, TokenError
#NEMĚNIT CUSTOM SBÍRANÍ COOKIE TOKENU #NEMĚNIT CUSTOM SBÍRANÍ COOKIE TOKENU
class CookieJWTAuthentication(JWTAuthentication): class CookieJWTAuthentication(JWTAuthentication):
def authenticate(self, request): def authenticate(self, request):
raw_token = request.COOKIES.get('access_token') raw_token = request.COOKIES.get('access_token')
if not raw_token: if not raw_token:
return None return None
validated_token = self.get_validated_token(raw_token) try:
return self.get_user(validated_token), validated_token validated_token = self.get_validated_token(raw_token)
return self.get_user(validated_token), validated_token
except (InvalidToken, TokenError):
# Invalid/expired token - return None instead of raising exception
# This allows AllowAny endpoints to work even with bad cookies!!
return None