Files
abyssVpn/services/api/common/auth.py
T
arthur_chen f69efb67ad Initial commit: abyssVpn project
- Tauri desktop app (apps/desktop)
- Python Django API service (services/api)
- Deployment scripts and docs
2026-05-15 09:06:10 +08:00

17 lines
492 B
Python

from django.http import HttpRequest
from accounts.models import User
from accounts.services.jwt_service import decode_jwt
def get_current_user(request: HttpRequest) -> User | None:
auth = request.headers.get("Authorization", "")
if not auth.startswith("Bearer "):
return None
try:
payload = decode_jwt(auth.removeprefix("Bearer ").strip())
return User.objects.get(id=payload["sub"], status=User.STATUS_ACTIVE)
except Exception:
return None