Roles Issue - supabase

Hey !

I have an issue with roles

Here it is : in the app i’m working on, i have admins and users roles

I used the tutorial here : (Supabase authentication | WeWeb documentation)

Then : On my signup portal, I created another signup form for admins where I add in the user metadata a field with ‘role : admin’
=> in my handle_new_user() function, i added that if the field “role” is found and equals to admin, insert a row in the userRoles table with the userId and the Admin’s role ID (if not found, the User role Id)

In a nutshell, I manage user roles in supabase and need the changes to be effective in Weweb

Result : it works and adds the row… BUT I have to disable RLS to have a propper sync with weweb.

Should I enable RLS in read (select) for everyone ? What about safety ? or only for the auhenticated user based on His ID ? (maybe not optimal on published version)
What do you think about my process ? Anything else in mind ?

Thanks you ! have a great day. I will dig into user groups and access to pages soon :wink:

Any clues for a smarter integration ? or a solution without the roles ?

I also have a similar situation which is surely common.

Using the same login page for both admin + users, I was looking to navigate the user to different pages depending on their roles

The roles object is empty as shown in the screenshot.

Disabling RLS seems counterintuitive but is that the correct (and safe) solution?

I could make a specific admin login alternatively.

Hey !
You could make a different login but it won’t solve it all.
Whats your plan on weweb ? The scaling enables blocking pages to a group of user (and therefore matches your admin issues). (there are alternative but not as clean)

What I suggest you do is after login, redirect to a page where the check happends.
Therefore, if user is logged in you can acces his role and have strong RLS.
This page can be the home page or the page where user chooses between login and signup. (on page load if user is loggedin check role and redirect to the good page)

Does it answer your question ?