Change Header depending on whether the user is logged in or not | Community
Skip to main content
Level 2
May 3, 2023
Solved

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

  • May 3, 2023
  • 4 replies
  • 1886 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Alex_Terinte

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.

4 replies

krati_garg
Adobe Employee
Adobe Employee
May 3, 2023
Level 2
May 4, 2023

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

Fanindra_Surat
Community Advisor
Community Advisor
May 3, 2023

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?

 

Level 2
May 4, 2023

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.

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 3, 2023

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

Level 2
May 4, 2023

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)

Alex_TerinteAuthorAccepted solution
Level 2
May 4, 2023

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.