feat(proj): init

This commit is contained in:
vl.arkhangelskii
2026-09-21 04:06:43 +03:00
commit c956b94983
1076 changed files with 50876 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
from __future__ import annotations
from datetime import datetime, timedelta, timezone
from typing import Any
import jwt
from api.config import settings
def create_access_token(*, user_id: int, profile: dict[str, Any]) -> str:
now = datetime.now(timezone.utc)
payload = {
"sub": str(user_id),
"uid": user_id,
"fn": profile.get("first_name"),
"ln": profile.get("last_name"),
"un": profile.get("username"),
"iat": now,
"exp": now + timedelta(seconds=settings.jwt_ttl_seconds),
}
return jwt.encode(payload, settings.session_secret, algorithm="HS256")
def decode_access_token(token: str) -> dict[str, Any]:
return jwt.decode(token, settings.session_secret, algorithms=["HS256"])