© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
1 reply
lp

Advanced role systems similar to discord

Hey, I'm creating a chat app which shares a lot of features with Discord for a client. specifically, the roles feature
I want to create dynamic roles that can be added to users that allow the users to do certain actions in certain channels. For example, a role called "Advanced" would allow users to add reactions to messages in Channel A and Channel B, or create threads in Channel B, depending on configuration set by chat admins.

I'm wondering how to set up access policies for this. Here's where I'm heading...

I'd create these tables...
*
role
role
table with
id
id
and
name
name

*
role_user_assignment
role_user_assignment
table with
role_id
role_id
,
user_id
user_id
to give a user a role
*
role_channel_permission
role_channel_permission
table with
permission
permission
enum
"react" "reply_in_thread"
"react" "reply_in_thread"
and pointer to
channel_id
channel_id
,
role_id
role_id
to give users of a certain role a permission in a certain channel.

So for example to check if user can create a reaction to a message in a channel... I'd have role named "Reactors" with an assignment to a user, and there'd be a role_channel_permission for permission to "react" on Reactors role_id in a given channel.

Then the question is how to model the row level security for this?

I want to only allow insertion of the
message_reaction
message_reaction
on a message for users who have a role that has a role_channel_permission in the given channel to
"react"
"react"
.

Anyone have any examples of these "nested access policies with joins"?

Otherwise I know i could just write supabase functions to do this but it seems like something I could model with access policies...
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Discord-like role authorization
SupabaseSSupabase / help-and-questions
14mo ago
URGENT: Production systems down
SupabaseSSupabase / help-and-questions
3mo ago
Alternative to service_role key?
SupabaseSSupabase / help-and-questions
3y ago
How to make new role?
SupabaseSSupabase / help-and-questions
4y ago