Get current user session



  • Hi,

    So we're planning on switching from Discourse to NodeBB (currently sorting out a new set of forums ready for release). While NodeBB has been amazing so far, we've come into struggles with using a NodeBB account externally. In Discourse you can do http://example.com/session/current.json and get the current viewers user information. But with NodeBB we're unable to actually find a way of doing it.

    I've tried looking around the NodeBB GitHub but found nothing. I have also tried making a plugin for it, but can't get it to work that way either. So I'd love to know if there is already a way or if someone can help me out with my plugin:
    https://github.com/wrong7/nodebb-plugin-skunity/blob/master/skunity.js

    Any and all help is appreciated!

    Thank you 🙂



  • Anyone? 😞


  • Admin

    We could possibly add a /api/me page that returns some info about the current logged in user. What kind of info you need?



  • @baris Just a basic overview. Kinda like a JSON form of a users profile as if it was being viewed publicly. We do an AJAX request and get the information. Example from Discourse:

    {
       "current_user":{
          "id":7,
          "username":"nfell2009",
          "avatar_template":"/user_avatar/nfell2009/{size}/3095_1.png",
          "name":"nfell2009",
          "total_unread_notifications":16,
          "unread_notifications":0,
          "unread_private_messages":0,
          "admin":false,
          "notification_channel_position":null,
          "site_flagged_posts_count":0,
          "moderator":true,
          "staff":true,
          "title":"Your friendly neighbourhood moderator",
          "reply_count":727,
          "topic_count":35,
          "enable_quoting":true,
          "external_links_in_new_tab":true,
          "dynamic_favicon":false,
          "trust_level":4,
          "can_edit":true,
          "can_invite_to_forum":true,
          "should_be_redirected_to_top":false,
          "disable_jump_reply":false,
          "custom_fields":null,
          "muted_category_ids":[
    
          ],
          "dismissed_banner_key":null,
          "is_anonymous":false,
          "post_queue_new_count":0,
          "read_faq":true,
          "automatically_unpin_topics":true
       }
    }
    

    Thanks for your reply 🙂


  • Admin

    Alright since we already have this data when you go to /api/user/<userslug> we can just return the same info when you go to /me.



  • @baris That would be perfect!


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.