# Problem with RLS and roles/userRoles table

**URL:** https://community.weweb.io/t/problem-with-rls-and-roles-userroles-table/8998
**Category:** Ask us anything
**Tags:** authentication, supabase
**Created:** [June 7, 2024, 7:10am UTC](https://community.weweb.io/t/problem-with-rls-and-roles-userroles-table/8998 "2024-06-07T07:10:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![NaikeSR](https://avatars.discourse-cdn.com/v4/letter/n/57b2e6/32.png) [@NaikeSR](https://community.weweb.io/u/NaikeSR)
#### Post date: [June 7, 2024, 7:10am UTC](https://community.weweb.io/t/problem-with-rls-and-roles-userroles-table/8998/1 "2024-06-07T07:10:56Z")

</div>

Good morning,  
I am interfacing with RLSs in Supabase, after following entirely and correctly implementing users and roles I need to put policies in the “roles” and “userroles” tables as well.

Now, I enter the policies that I attach below but as soon as I enter them, WeWeb reports an error with the Supabase authentication plugin. **I don’t understand though, I entered the Service Role Key which is just to bypass all the RLSs within the database, why doesn’t this one override it? Is there some special implementation that needs to be implemented?**

I am attaching here the policies that I am trying to insert in the userroles table:

> CREATE POLICY admin\_select\_policy  
> ON public.userroles  
> FOR SELECT  
> USING (  
> EXISTS (  
> SELECT 1  
> FROM public.userroles ur  
> JOIN public.roles r ON ur.role\_id = r.id  
> WHERE ur.user\_id = auth.uid() AND r.role\_name = ‘Admin’  
> )  
> );

> CREATE POLICY admin\_insert\_policy  
> ON public.userroles  
> FOR INSERT  
> USING (  
> EXISTS (  
> SELECT 1  
> FROM public.userroles ur  
> JOIN public.roles r ON ur.role\_id = r.id  
> WHERE ur.user\_id = auth.uid() AND r.role\_name = ‘Admin’  
> )  
> );

I attach here the policies I am trying to insert in the roles table:

> CREATE POLICY admin\_select\_policy  
> ON public.roles  
> FOR SELECT  
> USING (  
> EXISTS (  
> SELECT 1  
> FROM public.userroles ur  
> JOIN public.roles r ON ur.role\_id = r.id  
> WHERE ur.user\_id = auth.uid() AND r.role\_name = ‘Admin’  
> )  
> );

Can any of you help me?

Thank you very much,  
Naike

---

<div class="post-metadata">

### Author: ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)
#### Post date: [June 7, 2024, 7:28am UTC](https://community.weweb.io/t/problem-with-rls-and-roles-userroles-table/8998/2 "2024-06-07T07:28:29Z")

</div>

I think more details about the WeWeb error might be beneficial. I’d also suggest testing if it works while impersonating users in the Supabase dashboard. Imo it is a plugin misconfiguration, but we shall see the errors.

---

<div class="post-metadata">

### Author: ![Alexis](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/alexis/32/13248_2.png) [@Alexis](https://community.weweb.io/u/Alexis)
#### Post date: [June 10, 2024, 3:29pm UTC](https://community.weweb.io/t/problem-with-rls-and-roles-userroles-table/8998/3 "2024-06-10T15:29:31Z")

</div>

Roles are fetched with your connected user when you login (or enter the page and was already logged in)  
This step does not use the service role key as it happen on the front end.

The user should be able to retrieve his own roles from the userRoles and Roles tables. (We fetch the userRoles table and ask to return the associated roles information in the query)
