https://supabase.com/ logo
#help
Title
# help
i

ian_

05/12/2022, 10:01 PM
hey, what would be the easiest way to restrict access to view/edit supabase data based on discord roles?
n

Needle

05/12/2022, 10:01 PM
Hello @ian_! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
i

ian_

05/12/2022, 10:19 PM
different people add my bots to their server and for each server it will create an item in a supabase table representing the server people can login with discord and if they have certain roles in certain servers they should be able to edit, say, a todo list for that server
g

garyaustin

05/12/2022, 10:24 PM
Where is the role stored?
n

Needle

05/12/2022, 10:24 PM
ian_ (2022-05-12)
i

ian_

05/12/2022, 10:24 PM
that's part of the question
it's in discord, the discord bot has access to who has what roles in a server
i could try keeping a supabase table in sync with the roles on the server
g

garyaustin

05/12/2022, 10:27 PM
Not familiar with discord, does the role get returned, or can it, on signin in any of the metadata for the user?
i

ian_

05/12/2022, 10:28 PM
i don't think so - because people have different roles in each server they're in. it's possible it can be but I doubt it, and it looks like supabase doesn't allow requesting info from a user
g

garyaustin

05/12/2022, 10:30 PM
You can use the discord api (assuming it has one) using http extension or with an external function like the new edge functions.
If the role is not in the jwt metadata, which sounds like no, then you will need a user and roles assigned to them table that can be used in RLS. You would have to populate that table somehow though with discord role and I can not help you with that.
i

ian_

05/12/2022, 10:38 PM
how do I use a table in RLS? i only see instructions for using the user id
looks like i just write an SQL query
g

garyaustin

05/12/2022, 10:41 PM
https://supabase.com/docs/guides/auth/row-level-security. RLS policy is just a where statement added on. So yes a query that returns true.
2 Views