Files
survive-backend/src/utils/jwt.py
2025-10-04 15:42:00 +02:00

22 lines
587 B
Python

from datetime import datetime, timedelta
import jwt
from src.utils.config import get
SECRET_KEY = get('jwt_secret')
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 6000
def create_access_token(data: dict, expires_delta: timedelta | None = None) -> str:
to_encode = data.copy()
if "sub" in to_encode:
to_encode["sub"] = str(to_encode["sub"])
expire = datetime.utcnow() + (expires_delta or timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES))
to_encode.update({"exp": expire})
token = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return token