Clerk Auth with Supabase in Nextjs 14 #22165
Replies: 2 comments
-
|
Not sure this can be done. Supabase sessions depend on the UUID sub in the access token and the refresh token to work. You can use createClient with an authorization header set to the Clerk jwt and have RLS work except for auth.uid() function has to be changed ( and any UUID user id columns have to be changed to use the Clerk sting user id. |
Beta Was this translation helpful? Give feedback.
-
|
Since you're building off Gary's answer here, the cleanest path in 2025 is Clerk's native third-party auth integration rather than the old JWT-template route — Clerk deprecated the On the database side, store your user-id columns as create policy "Users manage own rows"
on public.your_table
for all
using (auth.jwt()->>'sub' = user_id)
with check (auth.jwt()->>'sub' = user_id);That lets the rest of your app stay mostly as-is — you stop trying to fit Clerk into Supabase's auth session and just let RLS trust Clerk's token. And since you're on Next.js 14, you can drop the Supabase session-refresh juggling entirely and pass the Clerk token when you construct the client. It's a bit of upfront migration on the column types, but it's stable once it's in. I wrote up the full walkthrough here: 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.
-
I am building a project in Next Js 14. My current auth system uses supabase's auth functionalities. Everything from session management to db is powered by a supabase.
I am however trying to switch to clerk for authentication. The problem I am facing is how to link clerk's userID with my supabase auth table.
I do not want to change any code for session management etc, hence I am trying to figure how to pass user details from clerk to my supabase auth db so the rest of the application can work well.
Beta Was this translation helpful? Give feedback.
All reactions