Skip to content

fix: create users via the lnbits 1.x account api - #70

Merged
helloscoopa merged 1 commit into
mainfrom
xbuddhi/lnbits-v1-user-creation
Sep 23, 2026
Merged

helloscoopa merged 1 commit into
mainfrom
xbuddhi/lnbits-v1-user-creation

Conversation

@xbuddhi

@xbuddhi xbuddhi commented Sep 22, 2026

Copy link
Copy Markdown

Summary

Every /start from a new Telegram user currently fails:

[createWallet] Create wallet error: Not Found
[startHandler] Error with initWallet: Not Found

Not Found is a literal 404. The bot creates users through the usermanager extension, whose last release (v0.4.1) declares max_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 imports get_key_type and WalletTypeInfo, 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.

Call Before (404) After
GetUser POST /usermanager/api/v1/users/{id} GET /users/api/v1/user/{id}
CreateUserWithInitialWallet POST /usermanager/api/v1/users POST /users/api/v1/user → fetch wallet → rename
CreateWallet POST /usermanager/api/v1/wallets POST /users/api/v1/user/{id}/wallet
Wallets GET /usermanager/api/v1/wallets/{id} GET /users/api/v1/user/{id}/wallet

Two behaviour differences are absorbed inside the client, so call sites are unchanged (internal/telegram/start.go needed no edit — its existing create-then-fetch-wallet flow already matches 1.x):

  • Creating a user also creates its wallet, but names it lnbits_default_wallet_name and omits wallets from the response. So the wallet is fetched and renamed, preserving the <telegram id> (<handle>) convention the existing 1883 wallets use.
  • The bot passes a telegram handle as email, which 1.x rejects via is_valid_email_address, so it is no longer sent. admin_id has 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:

lnbits:
  admin_token: "<ACL token scoped to /users/api/v1>"

Test plan

  • go build ./...
  • go vet ./internal/lnbits/... ./internal/telegram/... (only a pre-existing text.go warning)
  • Every call verified against the live 1.6.0 instance with a real ACL token:
    • GET /users/api/v1/user/{id} → 200
    • POST /users/api/v1/user → 200, returns id
    • GET .../{id}/wallet → 200, adminkey present, name comes back as LNbits wallet (confirming the rename is needed)
    • PATCH /api/v1/wallet → 200, renamed
  • Scope confirmed: the token cannot spend (POST /api/v1/payments → 401) and cannot read admin settings (GET /admin/api/v1/settings → 403, rejected by the ACL itself)
  • Probe account cleaned up; instance back to 1884 wallets / 1884 accounts / 0 orphans
  • Deploy and confirm a real /start from a new Telegram user

Note: deleting a user via DELETE /users/api/v1/user/{id} soft-deletes its wallet but leaves the row with a dangling user — worth knowing if user deletion is ever automated.

🤖 Generated with Claude Code

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.
@xbuddhi xbuddhi added the urgent Live bug affecting users - needs prompt review label Sep 22, 2026
@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 525c1b6c-07e4-4e86-95ec-cc68c3b99981


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@helloscoopa
helloscoopa merged commit 0be85cf into main Sep 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

urgent Live bug affecting users - needs prompt review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants