Greetings! Thanks for raising this question in the Q&A forum.
Here are two approaches you can use depending on your setup:
Approach 1: Query Web Roles via Server Logic (Dataverse API)
This is the best fit if you are already using server logic to serve data to your SPA.
Step 1: Get the current user's Contact ID from the
Server.User object, which is available in server logic automatically.
Step 2: Query the
mspp_webroleset table filtered by that Contact ID using the intersection relationship, like this:
javascript
const contactId = Server.User.ContactId;
const result = await Server.Connector.Dataverse.RetrieveMultipleRecords(
"mspp_webroleset",
`?$filter=mspp_webrole_contact/any(c:c/contactid eq ${contactId})&$select=mspp_name,mspp_webroleid`
);
const roles = result.value.map(r => r.mspp_name);
return JSON.stringify({ roles });
Step 3: Make sure the server logic has table permissions configured to allow read access on the mspp_webrole table — otherwise the Dataverse call will be blocked silently.
Step 4: Call this server logic endpoint from your SPA and use the returned roles array to conditionally show or hide parts of your app.
Approach 2: Use a Liquid-Based Web API Endpoint (Simpler Alternative)
If you prefer a lighter approach without server logic, you can create a Liquid page template that outputs the current user's roles as JSON.
Step 1: Create a new Web Template in Power Pages with the following Liquid code:
{
"roles": [
{% for role in user.roles %}
"{{ role.name }}"{% unless forloop.last %},{% endunless %}
{% endfor %}
]
}
Step 2: Set the MIME type of the page to application/json so your SPA can consume it directly.
Step 3: Call this page URL from your SPA using a simple fetch() request and parse the returned JSON to filter your UI based on the roles.
Both approaches work well. The Liquid-based approach is simpler and requires no extra permissions setup, while the server logic approach gives you more flexibility if you need to combine role data with other server-side logic.
For reference, you can read more about server logic operations here: https://learn.microsoft.com/en-us/power-pages/configure/server-logic-operations
If this answer helps you kindly accept the answer which will help others who have similar questions.
Best Regards,
Jerald Felix.