groups functional & bugfixes
This commit is contained in:
@ -96,17 +96,21 @@ def get_current_user(
|
||||
|
||||
|
||||
def get_current_user_or_none(
|
||||
token: Annotated[str, Depends(oauth2_scheme)],
|
||||
db: Annotated[Session, Depends(get_db)],
|
||||
authorization: Annotated[Union[str, None], Header()] = None,
|
||||
) -> 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)
|
||||
if authorization:
|
||||
token = authorization.split()[1]
|
||||
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)
|
||||
else:
|
||||
return None
|
||||
except JWTError:
|
||||
return None
|
||||
user = get_user_by_username(db, username=token_data.username)
|
||||
|
||||
Reference in New Issue
Block a user