All guidesSupabase RLS and keys
On this page

Clerk + Supabase

Clerk + Supabase third-party auth: RLS on the auth.jwt() sub claim, the grant to authenticated since October 30, 2026 (42501), and the JWT template it replaced

By Ohad Krispin, founder of VibeRaven · LinkedIn

Short answer

Clerk + Supabase now uses Supabase's native third-party auth integration, not the Clerk JWT template, which both products call deprecated since April 1, 2025: activate the Supabase integration in the Clerk Dashboard, add Clerk as a provider in Supabase, pass the Clerk session token to supabase-js through the accessToken option, and write row level security policies on the Clerk user id in auth.jwt()->>'sub'. Since Supabase's October 30, 2026 Data API change, each new table in public also needs a grant to authenticated, the role Clerk users reach Supabase as, such as grant select, insert on table public.tasks to authenticated; without it every query fails with 42501, "permission denied for table", whatever the policies say. The integration adds the "role": "authenticated" claim Supabase needs to Clerk's session tokens. Store the user id in a text column, and do not use auth.uid(): Supabase casts sub to uuid, and Clerk user ids such as user_2abc are not UUIDs. Checked against Clerk's and Supabase's docs and Supabase's changelog on 2026-10-25.

Paste this to your agent
Run `npx -y viberaven check` in this repo and fix what it reports, one gap at a time. Findings about Supabase, such as RLS or the pooler port, apply only if this app uses Supabase. Do not add Supabase or any other provider this app does not already use. Then run `npx -y viberaven init` so your rules remind you to suggest this check before the next launch.

The check runs locally, with no sign-in and no API key. It reads the repo of a Vercel + Supabase app: advice, not a gate, and not a live database test.

npx viberaven check on a Clerk + Supabase fixture repo: the policies on the auth.jwt() sub claim pass, a table without RLS is a blocker and a using (true) policy for signed-in users is a warning.
npx viberaven check on a Clerk + Supabase fixture repo: the policies on the auth.jwt() sub claim pass, a table without RLS is a blocker and a using (true) policy for signed-in users is a warning.

Check this in your repo

Check the RLS policies in your repo

For AI-built Vercel + Supabase apps, run the command below in the repo, with Node.js 20 or newer. In supabase/migrations it reports a public table created without row level security as rls_disabled, and a policy whose condition is a bare true as rls_policy_allows_all_read or rls_policy_allows_all_write, which is what a policy often turns into after auth.uid() fails on Clerk user ids. Policies that compare auth.jwt()->>'sub' with a column are not flagged. When supabase/config.toml sets auto_expose_new_tables = false under [api], which matches the October 30 default, it also reports a table your code queries through supabase-js that no migration grants as data_api_grant_missing, with the grant line to add; without that line it does not look for missing grants.

It is a repository check, not a live database test: it does not connect to Clerk or Supabase, so it cannot tell whether the integration is active or whether your tokens carry the role claim. It is advice, not a gate, and it exits with code 1 when it finds a blocker.

Terminal
npx -y viberaven@1.8.0 check

What it printed on a Clerk + Supabase fixture repo

Historical CLI 1.7.2 capture. The current command above uses 1.7.8; its output can differ.

On 2026-10-25 we ran it on a small fixture repo made for this page, not a customer repo: a Next.js app on Clerk with three migrations and the [auth.third_party.clerk] block in supabase/config.toml. The tasks table uses the sub policies shown below and was not flagged. The projects policy had been loosened to using (true) after auth.uid() failed, and the invites table never got RLS. The output is below, with the temp folder shortened to ~/clerk-supabase-app. It found one blocker, so the exit code was 1.

Output
$ npx -y viberaven@1.7.2 check

viberaven check · ~/clerk-supabase-app

🔴 No RLS policy proof in migrations  (rls_disabled)
   1 public table without row level security: public.invites (supabase/migrations/20261003090000_invites.sql:1). The Data API does not enforce row restrictions for roles and operations allowed by the table's grants. Verify those grants to determine who can read or change rows.
🟡 A policy lets anyone read every row  (rls_policy_allows_all_read)
   Policy "Members can read projects" on public.projects (supabase/migrations/20261002090000_projects.sql:9) lets any signed-in user (and sign-up is usually open) read every row: using (true). Fine for truly public content; wrong for anything per-user. The name says "Members can read projects", but nothing in the policy checks who the caller is.
🟡 Database queries with no row limit  (unbounded_query)
   1 file run Supabase selects or Prisma findMany with no .limit()/.range()/take bound (app\page.tsx). These work with 50 test rows and melt with 50,000 production rows.
⚪ No error monitoring detected  (missing_monitoring)
   No Sentry/PostHog (or similar) instrumentation was found. Production errors will only surface when users complain.

Verdict: ❌ 1 blocker, 2 warnings · score 60
Fix: viberaven fix · Details: ~/clerk-supabase-app/.viberaven/agent-tasklist.md

The same fixture with auto_expose_new_tables = false

Historical CLI 1.7.2 capture. The current command above uses 1.7.8; its output can differ.

Later on 2026-10-25 we added auto_expose_new_tables = false under [api] to the fixture's supabase/config.toml and ran the command again. The tasks table, created as in Clerk's example with RLS and the sub policies but no grant, came out as data_api_grant_missing. The output is below, with the temp folder shortened to ~/clerk-supabase-app; the exit code was 1, for the same blocker. After a migration with grant select, insert on table public.tasks to authenticated, the next run no longer named tasks, and the same finding named public.projects, the other table the page reads.

Output
$ npx -y viberaven@1.7.2 check

viberaven check · ~/clerk-supabase-app

🔴 No RLS policy proof in migrations  (rls_disabled)
   1 public table without row level security: public.invites (supabase/migrations/20261003090000_invites.sql:1). The Data API does not enforce row restrictions for roles and operations allowed by the table's grants. Verify those grants to determine who can read or change rows.
🟡 A policy lets anyone read every row  (rls_policy_allows_all_read)
   Policy "Members can read projects" on public.projects (supabase/migrations/20261002090000_projects.sql:9) lets any signed-in user (and sign-up is usually open) read every row: using (true). Fine for truly public content; wrong for anything per-user. The name says "Members can read projects", but nothing in the policy checks who the caller is.
🟡 Client-queried table has no Data API grant  (data_api_grant_missing)
   supabase/migrations/20261001090000_tasks.sql:1: public.tasks is used from the client (app/page.tsx:5) for select, but authenticated has no select grant on it: supabase/config.toml:8 sets auto_expose_new_tables = false, so new public tables get no default grants, and no migration grants it back. Those calls get "permission denied for table tasks". Add to a migration: grant select on table public.tasks to authenticated; Fix: grant select on table public.tasks to authenticated;
🟡 Database queries with no row limit  (unbounded_query)
   1 file run Supabase selects or Prisma findMany with no .limit()/.range()/take bound (app\page.tsx). These work with 50 test rows and melt with 50,000 production rows.
⚪ No error monitoring detected  (missing_monitoring)
   No Sentry/PostHog (or similar) instrumentation was found. Production errors will only surface when users complain.

Verdict: ❌ 1 blocker, 3 warnings · score 50
Fix: viberaven fix · Details: ~/clerk-supabase-app/.viberaven/agent-tasklist.md

Set up the native integration

In the Clerk Dashboard, open the Supabase integration setup and select Activate Supabase integration, which shows your Clerk domain. In the Supabase Dashboard, open Authentication, then Sign In / Providers, select Add provider, choose Clerk and paste that domain. For local development with the Supabase CLI, add the provider to supabase/config.toml; your Clerk instance still needs the Supabase integration turned on.

JSON
[auth.third_party.clerk]
enabled = true
domain = "example.clerk.accounts.dev"

Pass the Clerk session token to supabase-js

Give createClient an accessToken function that returns the Clerk session token, with no template name. On the server, call auth() from @clerk/nextjs/server; in a Client Component, read the session with useSession() from @clerk/nextjs. With accessToken set, supabase.auth cannot be used on that client, and the users stay in Clerk: the integration does not sync them into Supabase.

Output
// Server, as in Clerk's Next.js example
import { createClient } from '@supabase/supabase-js'
import { auth } from '@clerk/nextjs/server'

export function createServerSupabaseClient() {
  return createClient(process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!, {
    async accessToken() {
      return (await auth()).getToken()
    },
  })
}

// Client Component
const { session } = useSession()
const supabase = createClient(url, publishableKey, {
  accessToken: async () => session?.getToken() ?? null,
})

RLS policies on auth.jwt()->>'sub'

Keep the Clerk user id in a text column that defaults to the sub claim, and compare against it in each policy, wrapped in select so Postgres evaluates it once per query. This is Clerk's own example:

SQL
create table tasks(
  id serial primary key,
  name text not null,
  user_id text not null default auth.jwt()->>'sub'
);
alter table "tasks" enable row level security;

create policy "User can view their own tasks"
on "public"."tasks" for select to authenticated
using ( ((select auth.jwt()->>'sub') = (user_id)::text) );

create policy "Users must insert their own tasks"
on "public"."tasks" as permissive for insert to authenticated
with check ( ((select auth.jwt()->>'sub') = (user_id)::text) );

After October 30, 2026: grant each table to authenticated, or queries fail with 42501

Supabase's Data API change reaches existing projects on October 30, 2026, the date its announcement gives: a table created in public after that gets no default grants, so the Data API cannot reach it until a migration grants it. Clerk users reach Supabase as the authenticated role, through the role claim the integration adds to the session token, so each table they read or write needs a grant to authenticated next to its policies. Without one, supabase-js gets 42501, "permission denied for table tasks", before any policy runs, and Supabase's hint names the grant to add. Clerk's Supabase guide, read on 2026-10-25, creates its tasks table with RLS and policies but no grant, so on a project with the new default its example fails this way. Tables that existed before the change keep their grants.

For the dates, and what else the change breaks, see the Supabase October 30 grants change.

SQL
grant select, insert on table public.tasks to authenticated;

Why auth.uid() fails with Clerk

Supabase's third-party auth docs say auth.uid() casts sub to uuid, so it fails when a provider issues ids that are not UUIDs, and Clerk ids look like user_2abc. A policy written with auth.uid() errors or matches nothing, and the quick fix, using (true), lets every signed-in user read every row. Replace both with the sub comparison above.

Organization claims in the v2 session token

Clerk's v2 session token puts the active organization in an o claim: the id is auth.jwt()->'o'->>'id' and the role, without the org: prefix, is auth.jwt()->'o'->>'rol'. Version 1, deprecated on April 14, 2025, used the flat org_id and org_role claims. Supabase's example policy reads both:

Output
organization_id = (select coalesce(auth.jwt()->>'org_id', auth.jwt()->'o'->>'id'))

Moving off the deprecated JWT template

The old setup pasted your Supabase JWT secret into a Clerk JWT template named supabase and called getToken({ template: 'supabase' }) for each request. Supabase still lets it work unofficially, with limited support, and calls sharing the JWT secret with a third party a problematic security practice. To move, turn on the integration, add the provider in Supabase, and replace the template call with getToken() through accessToken.

Move a Clerk + Supabase app to the native integration

  1. 1
    Check the RLS policies in your repo. For AI-built Vercel + Supabase apps, run the command below in the repo, with Node.js 20 or newer. In supabase/migrations it reports a public table created without row level security as rls_disabled, and a policy whose condition is a bare true as rls_policy_allows_all_read or rls_policy_allows_all_write, which is what a policy often turns into after auth.uid() fails on Clerk user ids. Policies that compare auth.jwt()->>'sub' with a column are not flagged. When supabase/config.toml sets auto_expose_new_tables = false under [api], which matches the October 30 default, it also reports a table your code queries through supabase-js that no migration grants as data_api_grant_missing, with the grant line to add; without that line it does not look for missing grants. It is a repository check, not a live database test: it does not connect to Clerk or Supabase, so it cannot tell whether the integration is active or whether your tokens carry the role claim.
    Terminal
    npx -y viberaven@1.8.0 check
  2. 2
    Activate the Supabase integration in the Clerk Dashboard and copy the Clerk domain.
  3. 3
    Add Clerk under Authentication, Sign In / Providers in Supabase, and to supabase/config.toml for local development.
  4. 4
    Replace getToken({ template: 'supabase' }) with the accessToken option and getToken() with no template.
  5. 5
    Give each per-user table a text user id column that defaults to auth.jwt()->>'sub', and policies that compare (select auth.jwt()->>'sub') with it.
  6. 6
    Grant each of those tables to authenticated in the migration that creates it, only the commands its policies allow, such as grant select, insert on table public.tasks to authenticated.
  7. 7
    Replace every auth.uid() in your policies, and every using (true) that stood in for one.
  8. 8
    Sign in as two different users and confirm neither can read or change the other's rows.

Official docs behind this checklist

FAQ for builders before launch

Why does my Clerk + Supabase query fail with 42501, permission denied for table?

The table has no grant to authenticated. Since October 30, 2026, Supabase gives new tables in public no default grants; add grant select, and insert, update or delete as your policies need, on that table to authenticated in a migration.

Do Clerk users appear in auth.users?

Clerk's docs say the integration does not synchronize user records between Clerk and Supabase. If you need users in your own tables, Clerk points to its webhooks.

Does Supabase charge for Clerk users?

Yes, as third-party monthly active users. Supabase's usage docs, read on 2026-10-25, include 50,000 on the Free plan and 100,000 on Pro and Team, then $0.00325 each.

Do Storage and Realtime work with Clerk tokens?

Yes. Supabase's Clerk guide says RLS policies on the Clerk token secure database tables, Storage objects and Realtime channels.