Fixed UTC time

This commit is contained in:
2023-01-25 16:02:28 +01:00
parent 9a48835fe4
commit e14b3e7db3
3 changed files with 13 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import List, Union
from modules.database import col_users
@@ -82,9 +82,9 @@ def authenticate_user(user_name: str, password: str):
def create_access_token( data: dict, expires_delta: Union[timedelta, None] = None ):
to_encode = data.copy()
if expires_delta:
expire = datetime.utcnow() + expires_delta
expire = datetime.now(tz=timezone.utc) + expires_delta
else:
expire = datetime.utcnow() + timedelta(days=ACCESS_TOKEN_EXPIRE_DAYS)
expire = datetime.now(tz=timezone.utc) + timedelta(days=ACCESS_TOKEN_EXPIRE_DAYS)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt