Different menu items for different user roles. how?

Hello everyone!

I am wondering how would I achieve having different menu items for different user roles?

I did it before with RG and Do a search for with constraints but it is slow and inefficient and apparently I am supposed to use option sets for it

So let’s say i have 3 different user roles in option set

Where would I store my menu items and how would I achieve showing them depending on user role? Thank you

Have an option set for the menu items…then on that option set add a new attribute and make it the option set for user role…then you can setup a RG with menu items and filter by the user role attribute

1 Like

is it correct or not?

i never used filtered or option sets so not sure

Yes, using option sets for your menu items will be faster…

Here’s how I do it…

  1. create an option set for your user roles, and add the options (e.g. Admin, Creator, User etc.). Add whatever attributes you need to the option set (as you would with database fields). Make sure to add this as a field on your User datatype, and set each User’s value.

  2. Create an option set for your menu items, and add your options. Have an attribute on this option set called something like ‘User Role Access’, set it to the type of your ‘User Roles’ option set, and make it a list.

  3. Set the ‘User Role Access’ attribute on each Menu Item to contain whichever User Roles you want to have access to that menu item.

  4. Then, create a RG on your page with content type Menu Items (your option set) with a datasource of ‘All Menu Items’: filtered: User Role Access contains Current User’s User Role.

That will show only the Menu items’ who’s defined user roles contains the current user’s user role.

(note this only works if a user can only have a single user role. If a user can have multiple user roles you’ll need to use ‘intersect with: count >0’ instead of ‘Contains’.)

2 Likes

No that is not correct.

@adamhholmes took to the time to explain the same approach I outline in great detail for you to follow along.

2 Likes

oh wow this is a proper description of the process!

intersect with - also never used it just yet so thank you for this pointer!

I think I got it right now (correct me if I am wrong again)

Yes, that should work.

1 Like

awesome! thank you so much

To me it seems like the best option so far, but I am not bubble master just yet lol haha. One question - will it slow down my app considerably or not? someone in another group said it’s better to have as many RGs as I have user roles and show those groups depending on user roles? :confused:

I don’t see why it should. Maybe if you had hundreds or thousands of menu items and user roles it might - but I’ve never experienced any slowness using that method on my apps with a handful of user roles, and half a dozen or so menu items. And using option sets instead of database entries, and relating everything to the current user, should be fast as there’s no searching of the database.

But there are always multiple approaches to the same problem though, so having one RG with conditional datasources, or multiple RGs, are all valid options.

The best thing is to try one and see how it works - if it doesn’t work well for your app then try an alternative and see how it compares.

1 Like

thank you very much for explaining it to me and your help, Adam! What you saying does make a lot of sense + you tested it yourself so that’s great. I agree everything can be done in a lot of diff ways in bubble!

Your option seems more logical to me as doesn’t require making 3 RGs with seems excessive and hard to maintain, trying to do the least possible work as a principle here :smiley:

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.