While accessing a power page (site), we do perform local Microsoft authentication. Like every user, when entering the site's URL, it goes through Single Sign-On (SSO) and routes to the power page. Is there any way to retrieve the user's email ID in power pages? In Power Apps, we can obtain the user's email using 'User().Email'. Is there a similar method to retrieve the current user in power pages?.
FYI., we don't have azure subscription.
I have used the below Logic, i get "Hello, anonymous user"
```
If the email address is stored in Dataverse (which it would be if you are using Local Authentication or Claims mapping is configured correctly for External Identity providers then it is available via Liquid.
The Liquid 'user' object is the Dataverse Contact record, when a user is logged into the portal the 'user' object will exist and all the contact fields are available (except field types that are not supported b the portal).
As an example (note: in the designer it will not populate the value, only when you are logged into the site e.g. via preview, if you are not logged into the site you will get the anonymous user message)
{% if user %}
Hello, {{ user.fullname | escape }}!<br>
{{ user.emailaddress1 }}
{% else %}
Hello, anonymous user!
{% endif %}
Hi @eswarcareless ,
The simple answer is NO, you cannot get it in Power Pages using user object.
Thanks,
Saud
If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.
Hi @eswarcareless,
unfortunately the email is not easily possible.
You can use the id or the fullname as you already do:
<p id="userName">{{ user.fullname }}</p>
<p id="userId">{{ user.contactid }}</p>
What I do to send a message is the following:
{% assign userRoles = user.roles %}
{% for roleItem in userRoles %}
{% if roleItem == 'RoleWhichYouWantToCheck' %}
<p id="message" style="display: none">YourMessage<p>
{% endif %}
{% endfor %}
That way you can display a message if the user is anonymous or authenticated.
I use that code snippet for a custom role and display a message afterwards.
Hope that helps. Please mark the post as a solution if it solves your problem or consider a thumbs up when it helps.
WarrenBelz
146,769
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,091
Most Valuable Professional