Get current logged in user in clientlibs AEM 6.4 | Community
Skip to main content

6 replies

Ravi_Pampana
New Participant
Dec 13, 2018 6:21 PM UTC

Hi Arun,

Thanks for the details. But when I tried in AEM 6.4 and AEM 6.4 SP2 I am able to see CQ_User variable, not sure whether it is added back

Translate
arunpatidar
New Participant
Dec 13, 2018 7:12 PM UTC

Ahh ok, that means it is available in current version of AEM 6.4

Translate
Arun Patidar
Ravi_Pampana
New Participant
Dec 13, 2018 5:57 PM UTC

In author mode, we can read the current user/details by below variable

CQ_User

CQ_User.data.userID

Hope this helps

Translate
arunpatidar
New Participant
Dec 13, 2018 6:06 PM UTC

Hi Ravi,

I've just checked this in 6.3 and found CQ_User.data.userID works only in Classic UI whereas Granite.HTTP.externalize('/libs/granite/security/currentuser.json'); Ajax approach is compatible with both UI.

Translate
Arun Patidar
selvaganesh
Level 5
Dec 13, 2018 5:14 PM UTC

function getLoggedInUserID() {

        var currentUserId = "";

        var currentUserInfo;

        var CURRENT_USER_JSON_PATH = Granite.HTTP.externalize('/libs/granite/security/currentuser.json');

        var result = Granite.$.ajax({

            type: "GET",

            async: false,

            url: CURRENT_USER_JSON_PATH

        });

        if (result.status === 200) {

            currentUserInfo = JSON.parse(result.responseText);

            currentUserId = currentUserInfo.authorizableId;

        }

        return currentUserId;

    }

Translate
arunpatidar
New Participant
Dec 13, 2018 5:55 PM UTC

Thanks for sharing.

Translate
Arun Patidar