Expand my Community achievements bar.

SOLVED

Change Header depending on whether the user is logged in or not

Avatar

Level 3

Hello, good afternoon.

 

I am having some problems to be able to modify the header depending on whether a user is logged in or not.

 

I have 2 experiences fragments, one for anonymous user (Header) and another experience fragment for logged in users.

 

The thing is that I don't know what is the best way to make it work, I have tried to make requests to the /system/sling/info.sessionInfo.json file and change the header depending on the response, but in the Cloud environment it doesn't exists or the path is different. Besides, I don't think that way of doing it is very safe.

 

Can someone guide me a little on this topic?


Thank you so much.

1 Accepted Solution

Avatar

Correct answer by
Level 3

I was able to fix it. What I did was use ${currentSession.userID}
In case someone wants to use it.

 

It returns the ID of the user logged into the system.

View solution in original post

7 Replies

Avatar

Level 3

I have not tested it with that feature.

Thank you very much for the information, I'll try it and see if it adapts to what we need

Avatar

Community Advisor

Hi @Alex_Terinte ,

 

Are you trying to identify if the user is logged in or not?

Or Are you trying to figure out how to toggle the header after identifying the login state?

 

Avatar

Level 3

The way I have it done (Author and local) I first check if there is a token inside /system/sling/info.sessionInfo.json and see if the user data is empty.

 

If it is empty, it means that it is not logged in, and if it is filled in with the user's email, it means that it is logged in.

 

The thing is, that way only works on author or local, but not on publish.

 

Besides, I don't think it's very safe to do it that way.

Avatar

Community Advisor

Hi, is this the author? or public website behind a dispatcher?

Avatar

Level 3

We want it on both sites, both author and publish.

 

Although I understand that in author it would not make much sense since there will always be a logged in user (Our user as administrator)

Avatar

Correct answer by
Level 3

I was able to fix it. What I did was use ${currentSession.userID}
In case someone wants to use it.

 

It returns the ID of the user logged into the system.