Fetching user roles on client side

Maybe @patrick can advise here

Use two tables as shown here,one for user details, a second for permissions.

Bumping this post just in case there are others who wants an alternative to @jowhiskey’s solution.
Instead of creating another column for the “collective” permissions, we can create an array in Server Actions Step to “join” all the permissions as “comma-separated” so we can get it as a string. And on the page, we can do the “contain” filter to be used in the conditional region.

Server Actions:
image

Don’t forget to check on the “output” button so it will return back the result to the page (we can disable the output for the others as we don’t need them).

On the our page, we can do a:
{{serverconnect1.data.privileges_array.contains("admin")}}
This will return a Boolean value, whether it is true or false.

This can be implemented together with @Hyperbyte’s solution on how to use 2 tables for the security permission. But since the security permission only secure the database queries and the page access, we’ll need @jowhiskey’s solution to secure elements on the page or show something on the page depending on the user’s permission.

Hope this helps.

1 Like

Just another alternative. Instead of using the repeat.join as above, you can let SQL do the heavy lifting with a custom query as below.

SELECT GROUP_CONCAT(user_permissions.permission_level SEPARATOR ', ') as privileges
FROM user_permissions
WHERE user_permissions.permission_userid=:P1
GROUP BY user_permissions.permission_userid;

Just set up parameter :P1 to point to your user ID variable, and set the schema to output privileges.

1 Like