Skip to content

row-level security policies in Supabase for a multitenant application #149922

Discussion options

You must be logged in to vote

No need to worry, RLS can be a bit tricky at first, but I’ll walk you through it... :D

First, it looks like you’re on the right track with your policy, but there’s a small misunderstanding. The auth.uid() function returns the UUID of the currently authenticated user, not the tenant_id. If your tenant_id is stored in a different way (e.g., in a profiles table or as a custom claim in the JWT), you’ll need to adjust your policy accordingly.

Here’s an example of how you can set this up:

  1. Assume you have a profiles table that stores the tenant_id for each user. You can create a policy that joins the profiles table to enforce the restriction:
CREATE POLICY "Tenant can access their own data"
ON

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kirigakure0000
Comment options

Answer selected by kirigakure0000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants