f69efb67ad
- Tauri desktop app (apps/desktop) - Python Django API service (services/api) - Deployment scripts and docs
17 lines
492 B
Python
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
|
|
|