Cookie not updating upon login successfully with another account in Sling Model AEM | Community
Skip to main content
VuongNguyen
Level 2
Aug 26, 2022 7:26 AM UTC
Solved

Cookie not updating upon login successfully with another account in Sling Model AEM

Hi, Folks. Currently, I've facing issues that happens in my AEM project.
Overall view, my system has three type of users.
- At Login Gateway, I've setup as variables named Person Status and save it into Cookie.
- At Dashboard screen, in Sling Model Java, I'm using function as below to get Cookie and make conditions for navigation.html (sidebar.html) as below.

Here is Sling Model Java.

@Override
public String getCookieStatus() {
return CookieUtils.getCookieValue(request, Constants.PERSON_STATUS_COOKIE_NAME);
}

And then AEM HTL in Navigation Component.

<p class="nav__menu-item-subtext --small"
data-sly-test="${navItem.navItemSubtextA && navModel.cookieStatus == 'A'}">
${navItem.navItemSubtextForA}
</p>
<p class="nav__menu-item-subtext --small"
data-sly-test="${navItem.navItemSubtextB && navModel.cookieStatus == 'B'}">
${navItem.navItemSubtextForB}
</p>
<p class="nav__menu-item-subtext --small"
data-sly-test="${navItem.navItemSubtextC && navModel.cookieStatus == 'C'}">
${navItem.navItemSubtextForC}
</p>

For the first time, when I logged into Person Status = A. Navigation keeps A to render UI for A. But, I've logged out and try with another Person Status = B. The request.getCookie() return A and keep everything's for A.
The only, add url?q=1 and I can see updates executed. Was that means, Person Status = 'B" and then I saw updates with B.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Aug 26, 2022 10:41 AM UTC

you should add this login in HTL because pages will be cached.

Get this value using client side by setting up another non HttpOnly cookie which can be access via javascript/clienside.

Arun Patidar

3 replies

Manu_Mathew_
New Participant
Aug 27, 2022 3:00 AM UTC

@vuongnguyen You could probably use a unique id as a query parameter for each user on the url , which will force the url to not cache and hit the server, in case there is some caching involved.

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Aug 26, 2022 10:41 AM UTC

you should add this login in HTL because pages will be cached.

Get this value using client side by setting up another non HttpOnly cookie which can be access via javascript/clienside.

Translate
Arun Patidar
Leela-Pavan-Kumar
Level 4
Aug 26, 2022 9:05 AM UTC

Hi @vuongnguyen ,

 

Just check whether your cookie is getting clear or not once you logout.

 

And make sure it should not get cached.

Translate