[feat] add authenticated_user_id decorator (#2566)
* feat: add `optional_user_id` decorator
This commit is contained in:
parent
7f628948c9
commit
fb17611207
1 changed files with 13 additions and 0 deletions
|
|
@ -158,6 +158,19 @@ async def check_user_exists(
|
||||||
return user
|
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:
|
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:
|
if user.id != settings.super_user and user.id not in settings.lnbits_admin_users:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue