finally, queue logic

This commit is contained in:
2024-04-14 01:19:20 +03:00
parent d716a92dac
commit c64958bb9d
15 changed files with 177 additions and 17 deletions

View File

@ -46,7 +46,7 @@ def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None
if expires_delta:
expire = datetime.now(timezone.utc) + expires_delta
else:
expire = datetime.now(timezone.utc) + timedelta(minutes=15)
expire = datetime.now(timezone.utc) + timedelta(weeks=2)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(
to_encode, jwt_config.SECRET_KEY, algorithm=jwt_config.ALGORITHM
@ -90,6 +90,24 @@ async def get_current_user(
return user
async def get_current_user_or_none(
token: Annotated[str, Depends(oauth2_scheme)],
db: Annotated[Session, Depends(get_db)],
) -> Union[schemas.UserInDB, None]:
try:
payload = jwt.decode(
token, jwt_config.SECRET_KEY, algorithms=[jwt_config.ALGORITHM]
)
username: str = payload.get("sub")
if username is None:
raise credentials_exception
token_data = schemas.TokenData(username=username)
except JWTError:
return None
user = get_user_by_username(db, username=token_data.username)
return user
async def get_current_active_user(
current_user: Annotated[schemas.User, Depends(get_current_user)],
):