Getting logged in user token

Technical Support
  • We are using cutom UI(for front-end) & own middleware to communicate with nodebb API's.

    When the user is logged in, we are using nodebb-write-api to register or login the user into nodebb.

    But any further request from middleware should carry the nodebb logged in user info in the request header by sending the logged-in user token.

    We found some reference from below

    Please suggest how to get logged in user token, so that we will store that token in middleware session. Any request going through middleware will read the session info to get nodebb logged-in user token & upend to every request header.

  • Is your custom front end communicating directly to NodeBB through the write API?

  • @pitaj
    No. Custom UI is communicating with our nodeJS middleware application. From our nodeJS middleware application, we are using NodeBB read & write API's.

    Our application requirement is only logged-in users should able to participate in the discussions. To handle the session & secure the NodeBB write & read API's we are routing through our nodeJS middleware.

    Discusion architecture
    We are auto-creating the users in NodeBB when user logged-in to our application with Email & auto-login to NodeBB. So we need login user session details for further APIs to show/hide some of feature like

    1. Can create topic
    2. Can we specific categories
    3. Can reply to post on specific categories


  • @vinu Hm... there are a couple approaches you can take here.

    1. You can either generate a specific user token for each logged in user, or
    2. You can generate a single master token, and use that with the appropriate _uid parameter for each user, or
    3. You can retrieve the cookie after login.

    It seems like you are trying to do #3, but you probably want to pick one of the first two options.

  • @julian said in Getting logged in user token:


    Thanks for the quick response. Really appreciate the way you are responding to the user queries.

    I am using point 2 to generate a token for the logged-in user using the master token.

    curl --location --request POST 'http://localhost:4567/api/v1/users/2/tokens?_uid=2' \
    --header 'Authorization: Bearer 840b285b-dee8-44d9-802d-a2cc0057e3ab' \
    --header 'Authentication: Bearer 840b285b-dee8-44d9-802d-a2cc0057e3ab' \


        "code": "ok",
        "payload": {
            "token": "a02c1803-9b8e-444e-892f-fef5d4ac257b"

    This is working fine to get the token for a specific user. Once I get the token for the logged-in user, I am using the above response token in the further API request header as below.

    curl --location --request GET 'http://localhost:3002/discussion/category/8?_uid=a02c1803-9b8e-444e-892f-fef5d4ac257b' \
    --header 'Authorization: Bearer a02c1803-9b8e-444e-892f-fef5d4ac257b' \
    --header 'Authentication: Bearer a02c1803-9b8e-444e-892f-fef5d4ac257b' \
    --data-raw ''

    But I am getting error as SESSION_EXPIRED(even though the user is logged-in in different browser)

        "id": "app.error",
        "ver": "1.0",
        "ts": "2020-12-30 09:16:22:415+0530",
        "params": {
            "msgid": null,
            "status": "failed",
            "err": "SESSION_EXPIRED",
            "errmsg": "Session Expired"
        "responseCode": "SESSION_EXPIRED",
        "result": {}
  • @vinu Ah, you'll want to pass an actual uid into the _uid query parameter, not a user token. I think that's the issue here.

Suggested Topics

  • 0 Votes
    5 Posts

    @sweetp glad to hear it 😎

  • 0 Votes
    4 Posts

    @crazycells nice and succinct, appreciate you helping out on the forums 😁

  • 0 Votes
    2 Posts

    Turn Hide user list and data from guests on in /admin/settings/user and hit save. You should also remove find/read privileges from guests if you don't want them to see content.

  • 0 Votes
    3 Posts

    @pichalite Yes. I have tested that if the user is not currently online, the user is able to receive email from executing the above code.

  • Error logs

    Solved Technical Support
    0 Votes
    1 Posts
    11/5 22:06 [2132] - error: /category/95.rss Error: BΕ‚Δ™dne ID Kategorii at async.waterfall.category.topics (/root/nodebb/src/categories.js:35:18) at fn (/root/nodebb/node_modules/async/lib/async.js:746:34) at /root/nodebb/node_modules/async/lib/async.js:1213:16 at /root/nodebb/node_modules/async/lib/async.js:166:37 at /root/nodebb/node_modules/async/lib/async.js:706:43 at /root/nodebb/node_modules/async/lib/async.js:167:37 at /root/nodebb/node_modules/async/lib/async.js:1209:30 at /root/nodebb/src/categories.js:168:4 at /root/nodebb/node_modules/async/lib/async.js:726:13 at /root/nodebb/node_modules/async/lib/async.js:52:16 at done (/root/nodebb/node_modules/async/lib/async.js:246:17) at /root/nodebb/node_modules/async/lib/async.js:44:16 at /root/nodebb/node_modules/async/lib/async.js:723:17 at /root/nodebb/node_modules/async/lib/async.js:167:37 at /root/nodebb/src/categories.js:234:4 at /root/nodebb/node_modules/async/lib/async.js:52:16