Show/Hide for roles/Permissions

Hi!

How do I hide or show buttons and links depending on permissions?
I tried to look for a solution in the forum but I couldn’t really find a solution.

What I try to achieve:
I need some of these links only to be shown for the role “admin”

What I tried:

  1. I created a “Role” field in the user table
  2. I created “admin” and “user” permissions in the security provider with conditions

  1. In the designer, I tried to use the Display-Show in dynamic attributes for the links that I want to be shown only for the “admin” role, but the “role” field doesn’t show up in the user details server connect list:

I’m sure it’s easy to do this I just couldn’t figure it out for the past couple hours… Can you help? :sweat_smile:

Unfortunately that isn’t available today.

You’ll need to output something to the client (set a variable or something like that) so you can base the show/hide on that.

2 Likes

Maybe this could be called a workaround, But it works.

  1. Create a server action called admin or similar

  2. first step is Security Restrict and admin for the permission

  3. second step is Database Single Query populated with one field. I have used UserID

  4. Add Server Connect to the page and bind it to the admin server action

Now, if the scAdmin data source contains data, the user is an Admin. As you can see, I have two paragraphs. The ’user paragraph is hidden when the user is an Admin. The other is shown when the user is an Admin.

2 Likes

Voted!

Thank you for the explanation Ben, will use this method then!

@ben Thank you very much for the explanation of your workaround. I think this would be really useful. Not only to show and hide buttons and links but also to show and hide other elements. How can we propose this to become a new useful feature?

1 Like

See Ken’s (@mebeingken) reply above

Here is a thought. In your onboarding create account flow, once a new user is created. You can add a condition that insert or update a separate field in your user database table that ties each role to a value let say this field is called tracker and has enum (1,2,3) where admin get 1, users get 2 & super users get 3, etc. Now in your registration flow you should have set your user table role and tracker fields defaults in the database by the enum default, so every on create each new users defaults to role = user and in your tracker field have it default to 2. This is given that you use enum for these fields currently else do it in your registration code flow when inserting new user set the defaults for those field values role and tracker. Now once you are ready to give users their role you can update the default roles along with their tracker value and when you want to hide something on a page query the user table tracker field values instead of the role field values and set the condition where role = tracker this will filter and bring back all role of users. Now when you want to hide/show elements browser side or from server side the tracker values already filter the query and you can user it however. Doing it this way will help on the browsers side not make the users role field available to be so obvious in the query when validating access level or hide/show or validating email verification link.

In other world you can help us by adding your vote to my request feature for auth0 this way we don’t have to build out our own login system and worry about zero day vulnerability and maintenance for your clients. Building your own login system is cool and all using Wappler but I would advise against doing so if one is really serious about going big time as a web developer because the risk of doing it in a closet is real especially when doing big clients project that already has auth0 integrate in their application.

Click the link and Help by adding your vote

How is your query set up?

If your query is outputting the role column it should appear.