Repository navigation
fix: create users via the lnbits 1.x account api - #70
Merged
Merged
Conversation
The bot creates telegram users through the usermanager extension, whose
last release caps at max_lnbits_version 1.0.0. The backend now runs 1.6.0,
where the extension cannot be installed at all - its imports of
get_key_type and WalletTypeInfo no longer exist - so every /start from a
new user failed with "Create wallet error: Not Found", a 404. Existing
users were unaffected, since their wallets were already on the instance.
Usermanager's functionality moved into core, behind account-level auth: a
wallet api key does not grant it, so account management now needs a bearer
token. Rather than put the superuser login in the config, take an ACL
token scoped to /users/api/v1, which can manage accounts but cannot spend
from any wallet or reach admin settings.
The token is kept in its own header, so wallet calls cannot present it
even by accident, and paying still goes through the wallet's own key.
Two behaviours differ from usermanager and are handled here rather than at
the call sites, which are unchanged:
- creating a user also creates its wallet, but names it after
lnbits_default_wallet_name and omits the wallets from the response, so
the wallet is fetched and renamed to keep the existing
"<telegram id> (<handle>)" convention.
- the bot passes a telegram handle as the email, which 1.x rejects as
malformed, so it is no longer sent. admin_id has no counterpart at all
and is now ignored.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every
/startfrom a new Telegram user currently fails:Not Foundis a literal 404. The bot creates users through the usermanager extension, whose last release (v0.4.1) declaresmax_lnbits_version: 1.0.0. The backend now runs lnbits 1.6.0, so the extension cannot be installed — and could not run if forced, since it importsget_key_typeandWalletTypeInfo, both removed in 1.x.Existing users are unaffected; their wallets already exist on the instance.
Approach
Usermanager's functionality moved into core, behind account-level auth — a wallet api key does not grant it. Rather than putting the superuser login in the bot config, this uses an ACL token scoped to
/users/api/v1: it can manage accounts but cannot spend from any wallet or reach admin settings.The token lives in its own
adminHeader, separate from the wallet-key header, so wallet calls cannot present it even by accident. Paying still uses the wallet's own admin key.GetUserPOST /usermanager/api/v1/users/{id}GET /users/api/v1/user/{id}CreateUserWithInitialWalletPOST /usermanager/api/v1/usersPOST /users/api/v1/user→ fetch wallet → renameCreateWalletPOST /usermanager/api/v1/walletsPOST /users/api/v1/user/{id}/walletWalletsGET /usermanager/api/v1/wallets/{id}GET /users/api/v1/user/{id}/walletTwo behaviour differences are absorbed inside the client, so call sites are unchanged (
internal/telegram/start.goneeded no edit — its existing create-then-fetch-wallet flow already matches 1.x):lnbits_default_wallet_nameand omits wallets from the response. So the wallet is fetched and renamed, preserving the<telegram id> (<handle>)convention the existing 1883 wallets use.email, which 1.x rejects viais_valid_email_address, so it is no longer sent.admin_idhas no counterpart in 1.x and is now ignored (parameter kept so callers don't change).Config
One new field. A wallet api key cannot do account management on 1.x, so this is required:
Test plan
go build ./...go vet ./internal/lnbits/... ./internal/telegram/...(only a pre-existingtext.gowarning)GET /users/api/v1/user/{id}→ 200POST /users/api/v1/user→ 200, returns idGET .../{id}/wallet→ 200,adminkeypresent, name comes back asLNbits wallet(confirming the rename is needed)PATCH /api/v1/wallet→ 200, renamedPOST /api/v1/payments→ 401) and cannot read admin settings (GET /admin/api/v1/settings→ 403, rejected by the ACL itself)/startfrom a new Telegram userNote: deleting a user via
DELETE /users/api/v1/user/{id}soft-deletes its wallet but leaves the row with a danglinguser— worth knowing if user deletion is ever automated.🤖 Generated with Claude Code