[feat] add authenticated_user_id decorator (#2566)

* feat: add `optional_user_id` decorator
This commit is contained in:
Vlad Stan 2024-07-04 17:24:20 +03:00 committed by GitHub
parent 7f628948c9
commit fb17611207
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -158,6 +158,19 @@ async def check_user_exists(
return user
async def optional_user_id(
access_token: Annotated[Optional[str], Depends(check_access_token)],
usr: Optional[UUID4] = None,
) -> Optional[str]:
if usr and settings.is_auth_method_allowed(AuthMethods.user_id_only):
return usr.hex
if access_token:
account = await _get_account_from_token(access_token)
return account.id if account else None
return None
async def check_admin(user: Annotated[User, Depends(check_user_exists)]) -> User:
if user.id != settings.super_user and user.id not in settings.lnbits_admin_users:
raise HTTPException(