Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@motorina0
Copy link
Collaborator

@motorina0 motorina0 commented Jun 26, 2025

Summary

This PR adds an optional external_id field to each user account. This means other systems can set this field for the LNbits users and then it can query by it.

The external_id can have max 256 characters without space or new line characters. The value can be seen by a user, but a regular user cannot update its own external_id, only admins are allowed.

It is ALLOWED for more users to have the SAME external id. This allows third party systems to have a one-to-one or a one-to-many relation between their users and LNbits users.

It can be set/updated via the Admin UI or via the API.

Admin UI

image

API call

See API test: test_update_user_success

  • update user external id
    • in this case two users have the same external_id, this is allowed
curl --location --request PUT 'http://localhost:5000/users/api/v1/user/8bb1c696640d4417a6f4ffde06020fa1' \
--header 'Cookie: cookie_access_token=eyJhbGc...' \
--header 'Content-Type: application/json' \
--data '{
    "id": "8bb1c696640d4417a6f4ffde06020fa1",
    "username": "empty",
    "external_id": "external_1234"
}'
  • get users by external id:
curl --location --request GET 'http://localhost:5000/users/api/v1/user?external_id=external_id_two' \
--header 'Cookie: cookie_access_token=eyJhbGc...'
{
    "data": [
        {
            "id": "a8f1abc9c1ec4000ab2df560789963bd",
            "external_id": "external_id_two",
            "username": "admin",
            "extra": {...},
            ...
        },
        {
            "id": "edc30a66312543c0a1df5a10ca094111",
            "external_id": "external_id_two",           
            "extra": {...},
            ...
        }
    ],
    "total": 2
}

@codecov
Copy link

codecov bot commented Jun 26, 2025

Codecov Report

Attention: Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.

Project coverage is 60.51%. Comparing base (ff24847) to head (f2c0c25).
Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
lnbits/helpers.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #3219      +/-   ##
==========================================
+ Coverage   60.06%   60.51%   +0.45%     
==========================================
  Files         105      105              
  Lines       13810    13817       +7     
==========================================
+ Hits         8295     8362      +67     
+ Misses       5515     5455      -60     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@motorina0 motorina0 changed the title feat: add external id feat: add external id for users Jun 26, 2025
@motorina0 motorina0 requested review from arcbtc, dni and talvasconcelos and removed request for dni June 26, 2025 12:31
@motorina0 motorina0 marked this pull request as ready for review June 26, 2025 12:33
@dni dni merged commit 4247b9d into dev Jun 26, 2025
43 checks passed
@dni dni deleted the user_external_id branch June 26, 2025 13:33
dni pushed a commit that referenced this pull request Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants