supabase and role based authorization

Database & APIs

My app is a school related app. There are 3 types of users for my app:
1)Admin : who can do all the operation on a table

2)Teachers : who have limited access

3)Student : more limits compared to Teachers

I have been trying out multiple rls policies and most of them doesn't seem to work for some reason.

I have tried different method to access the table and none seems to work properly
https://files-us-east-1.t-cdn.net/files/WXfzRoQlhc2GVMNUEJvNL

Method 1

Screenshot 2025-01-29 172001.png
22.85KB

Only this one seems to work where I directly mention the admin's mail id. If I follow this method I will have to create a policy for every user in this app

Method 2

supabase-role-based : by James NoCode i have followed this YouTube video where he creates two tables' roles and user_roles and joins both of the table and access it by matching authenticated user's uuid and role. I followed the video exactly as shown but for some reason its not showing any rows when accessing tables

Method 3

i updated the auth.users table and assigned the specific role to the authenticated user using the sql command

UPDATE auth.users SET role = 'admin' WHERE id = 'user-id-to-update';

Now how do I add rls policy based on this where condition should look like this ,

auth.users.role = 'admin'

eg: there is a template option similar to this

  (select auth.jwt()) ->> 'email' = email
What have you tried so far?

1)hardcoding the gmail in rls policy

2)By using a user_roles table

3)Assigning role to users in auth.users table

Did you check FlutterFlow's Documentation for this topic?
No
2
5 replies