How to get current user details in Power pages/ Power Apps portals

Hello everyone and welcome to my blog. In today’s blog I will show how to get logged-in user information and use it dynamically in Power Apps portals/ Power Pages.

Using Liquid, an open-source template editing language, you can render dynamic content inside the pages. Liquids have objects and using them you can retrieve dynamic information related to website, page, settings, user etc.

Once such object is the user object using which you can get the details of the logged in user. Below is the liquid code to check if the a user has logged in to the portal and display a welcome message to the user.we

{% if user %}
Welcome, {{ user.fullname }}
(% else %}
You need to login to view this content
(% endif %}

Observe the usage of the fullname property. Using the user object you can display the value of any column in the user table. You can even display the value of complex field types like Choices and Lookups.

Below is an example to display the value of Choice field using Liquid user object

Gender Code: {{ user.gendercode.label }}

Below is an example to display the value of Lookup field using Liquid user object.

Parent Company label: {{ user.parentcustomerid.name }}
Parent Company Id: {{ user.parentcustomerid.id }}

That’s great. But how to get the logged in user web roles. The user object has roles property which help us do just that. Below is an example code to iterate through the user web roles.

{% assign userRoles = user.roles %}
{% for roleItem in userRoles %}
{% if roleItem == 'Administrator' %}
Welcome Administrator
{% endif %}
{% endfor %}

Hope you liked this post. For similar topics on Microsoft.NET and Power Platform, subscribe to my blog using the Subscribe option on right pane.

You will also like the below posts.

Debajit Dutta
Business Solutions MVP