Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

Avatar

Level 1

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

View solution in original post

3 Replies

Avatar

Level 4

Hi @LorenceNguyen ,

 

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

 

And make sure it should not get cached.

Avatar

Correct answer by
Community Advisor

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.

Avatar

Level 8

@LorenceNguyen 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.