Forum Discussion

sriray's avatar
sriray
Contributor
12 years ago

How do I get the currently logged-in user details like avatar, id and Name using Javascript?

Hi,   We are having a JS based widget that would need to display basic user details like the avatar, name and a unique id. Is this information available via cookies or can we make REST API call to ...
  • AdamN's avatar
    12 years ago

    There's a JavaScript object available called LITHIUM.CommunityJsonObject which has many details related to the current user and the page that they're on. For example:

     

    LITHIUM.CommunityJsonObject = {
      "User" : {
        "login" : "AdamN"
      },
      "Community" : {
        "id" : "lithium",
        "title" : "Lithosphere Community",
        "shortTitle" : "Lithosphere"
      },
      "Activity" : {
        "Results" : [ ]
      },
      "WebTracking" : {
        "path" : "Community:Lithosphere/Board:ask a question/Message:How do I get the currently logged-in user details like avatar, id and Name using Javascript?",
        "Activities" : { }
      },
      "CoreNode" : {
        "id" : "public-qa",
        "title" : "ask a question",
        "shortTitle" : "ask a question",
        "ancestors" : [
          {
            "id" : "lithium",
            "title" : "Lithosphere Community",
            "shortTitle" : "Lithosphere",
            "nodeType" : "Community"
          }
        ],
        "nodeType" : "Board"
      }
    };

     

    If this object doesn't have all the details that you need, you could always write out your own JavaScript object populated using a combination of FreeMarker and our REST API.

     

    I hope this helps!