fix: DeprecationWarning for datetime.utcnow() by using datetime.now(UTC)

This commit is contained in:
USIGLOBAL\daniel_tsai 2024-08-22 15:12:40 +08:00
parent e2b7296786
commit 89ebbed67b

View File

@ -6,7 +6,7 @@ from apps.webui.models.users import Users
from typing import Union, Optional from typing import Union, Optional
from constants import ERROR_MESSAGES from constants import ERROR_MESSAGES
from passlib.context import CryptContext from passlib.context import CryptContext
from datetime import datetime, timedelta from datetime import datetime, timedelta, UTC
import jwt import jwt
import uuid import uuid
import logging import logging
@ -40,7 +40,7 @@ def create_token(data: dict, expires_delta: Union[timedelta, None] = None) -> st
payload = data.copy() payload = data.copy()
if expires_delta: if expires_delta:
expire = datetime.utcnow() + expires_delta expire = datetime.now(UTC) + expires_delta
payload.update({"exp": expire}) payload.update({"exp": expire})
encoded_jwt = jwt.encode(payload, SESSION_SECRET, algorithm=ALGORITHM) encoded_jwt = jwt.encode(payload, SESSION_SECRET, algorithm=ALGORITHM)