mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 05:07:10 +00:00
fix: incorrect token 500
This commit is contained in:
@@ -5,15 +5,19 @@ import jwt
|
||||
from django.conf import settings
|
||||
from django.http import HttpRequest
|
||||
from ninja.security import HttpBearer
|
||||
from redis.exceptions import AuthorizationError
|
||||
|
||||
from apps.user.models import User
|
||||
|
||||
|
||||
class BearerAuth(HttpBearer):
|
||||
def authenticate(self, request: HttpRequest, token: str) -> Any | None:
|
||||
data = jwt.decode(token, settings.SECRET_KEY, algorithms=["HS256"])
|
||||
if data["exp"] < datetime.datetime.now().timestamp():
|
||||
return None
|
||||
try:
|
||||
data = jwt.decode(token, settings.SECRET_KEY, algorithms=["HS256"])
|
||||
if data["exp"] < datetime.datetime.now().timestamp():
|
||||
return None
|
||||
except Exception:
|
||||
raise AuthorizationError
|
||||
|
||||
user = User.objects.get(id=data["id"])
|
||||
return user
|
||||
|
||||
Reference in New Issue
Block a user