Replies: 7 comments 10 replies
-
|
These Clerk guides show a function that is needed and how they do generation of the custom token... https://supabase.com/partners/integrations/clerk |
Beta Was this translation helpful? Give feedback.
-
|
Yes - I know. I have them and I have made a creator_id on my events table that uses requesting_user_id() as its default value. However, I also have a user table (with a clerk webhook to make an entry in the user table when a clerk user is registered). The user table has an id (uuid) attribute and a clerk_id(string) attribute. i can see from the logs, that when I log the useUser details, the id returned is the clerk_id (prefix is user_). The user.id is a uuid and does not map to this value. So - if I want to make an RLS policy that says the signedInUser has a user.id that is the same as the event.host_id then the RLS policy would need to be something that checks if the host_id (uuid on the events table) is equal to the user.id (uuid on users table) that is unique to a clerk_id (string on the users table) that is equal to auth.uid(). I don't know how to write that in the RLS policy creator. I also think this seems very complicated. I could use the creator_id attribute on the events table (which should map to the auth.uid() value in an RLS policy, but then I need to make two user id keys on the events table. I think the clerk docs assume that I wont want to make a users table. If I do want a users table, is there a way to use a join in the RLS policy that lets me map auth.uid() (which is the saved value in users.clerk_id) to users.id to then match to events.host_id? |
Beta Was this translation helpful? Give feedback.
-
|
If I remove the host_id altogether and just use the events.creator_id (which is a foreign key to users.clerk_id). I can see these match and are generated in the same form, then I make a policy that looks just like the docs say: alter policy "allow create" on "public"."events" to authenticated with check ( 7 ); or alternatively trying without the authenticated constraint (so default to public): Use options above to edit alter policy "allow create" on "public"."events" to public with check ( 7 ); then i get an error that says: Event Action Error: { if the policy is set to true with no checks, then I can create the event. I can log the users.clerk_id and see that it is the same as the useAuth id from clerk. |
Beta Was this translation helpful? Give feedback.
-
|
the events table has an attribute named creator_id. that field is set with a default value of requesting_user_id(). I can see that this is working because I can make an entry in my events table, and the value stored in the creator_id field is the same as the clerk_id stored on my users table (which is the same as the id stored on the clerk users dashboard). the events table has the following properties. Name Type Primary uuid created_at timestamptz title text comment text 1 date date 1 time timetz 1 virtual bool 1 linkToVirtual varchar 1 status_id uuid 1 creator_id text 1 maxGroupSize int2 1 location text 1 Add column Foreign key relation to: public.status Edit Remove Foreign key relation to: public.users Edit Remove I'm not clear on whether the supabase roles documentation only applies to apps using supabase auth to manage users or if its for anyone authorising (by any means) to access supabase. I can't check because even when I set the insert event policy to true (but use the authenticated role instead of the public default), i still get an RLS violation (which I don't get if the public default is true). |
Beta Was this translation helpful? Give feedback.
-
|
I'm very grateful to you for trying to help me but I dont understand either of your comments. Step 6 of this supabase config instruction tells me how to configure supabase to incldue the headers. I've implemented it as follows: import { useSession } from '@clerk/nextjs'; export function useSupabaseClient() { const supabaseClient: SupabaseClient = useMemo(() => { useEffect(() => { }, [session, isLoaded, supabaseClient]); return { supabase: supabaseClient, isInitializing }; I can't see a role example in this documentation. I have set the value to the default (I'll come back to figuring out whether the supabase documentation on roles still applies when using clerk). I'm trying to focus on the requesting_user_id() aspect of this check for the moment. Given the value is default, then even if there is another configuraiton step documented somewhere that tells me how to include a role parameter, it shouldn't matter for now. I also don't understand your comment about the default value in the events table creator_id attribute. I typed in the value and it saved it in the format I shared. Whatever it was doing, it actually inserts the value of the clerk userId into the creator_id column - but in any event, I changed it to remove everything other than requesting_user_id() and if i set RLS to true, I can still make an event, and the creator_id still populates with the same user id value (which is the clerk id). If I try to add RLS as follows: Use options above to edit alter policy "users can edit their own proposals" on "public"."events" to public using ( 7 ); (noting that I type line 7 without the parenthesis but when i go back in to check it saved, they appear as added back) then I get an RLS violation. I am sure the clerk_id is the creator_id and i am sure I am logged in through clerk. |
Beta Was this translation helpful? Give feedback.
-
|
@MincePie Summery for this is | Free | ❌ | ❌ | Not possible | besause You see here in this image , we need to Configure Supabase to Accept Clerk JWTs , but this option we only seen in pro version Thanks |
Beta Was this translation helpful? Give feedback.
-
|
The problem is that auth.uid() casts the JWT sub to a uuid, but Clerk user IDs (user_2abc…) aren't UUIDs — so it errors or comes back null. Don't try to map it onto your uuid primary key. Two things fix it: Use Clerk's native Supabase integration (the old JWT-template method was deprecated in April 2025). In Supabase: Authentication → Third-Party Auth → add Clerk. That makes Supabase trust Clerk's token and adds the role: authenticated claim the policies need. Full breakdown with the client setup + that role-claim gotcha: https://www.guardlayer.io/blog/clerk-supabase-rls |
Beta Was this translation helpful? Give feedback.




Uh oh!
There was an error while loading. Please reload this page.
-
Im trying to figure out how to use RLS with supabase, where users are created via clerk webhook. My users table has an id attribute and a clerk_id attribute. I don't know why it is in that form.
I've just realised that the supabase RLS check for permitting users to interact with their own data, in the form suggested by its helpers, checks auth.uid() = table_id - where auth.uid() is referencing clerk_id. I can't make that my foreign key because its a string. user.id is a uuid so the tables that have an id (as a uuid) and which reference the id on the other table, also need to be a uuid.
is there a way to make clerk webhooks make a user where the user.id is used in the RLS policy so that auth.uid() is actually the user.id instead of the clerk_id?
Beta Was this translation helpful? Give feedback.
All reactions