diff --git a/lnbits/decorators.py b/lnbits/decorators.py index f6d04b1b7..f61c6c028 100644 --- a/lnbits/decorators.py +++ b/lnbits/decorators.py @@ -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(