In short
- Auth answers who is calling. It never answers what they may read. With either provider, that second answer is your policies or your server code.
- With Supabase Auth, policies use
auth.uid()and auuidcolumn. With Clerk, the integration guide usesauth.jwt()->>'sub'and atextcolumn. Policies do not carry over from one to the other. - Clerk's Supabase JWT template has been deprecated since 1 April 2025. The current setup is Supabase's third-party auth integration, which needs no shared JWT secret.
- Supabase's docs say Supabase Auth cannot be disabled when you add a third-party provider. If Clerk is your only door, close sign-up on the Supabase side.
- A Clerk webhook route is public by design. Verify the signature with
verifyWebhook()before you trust the body.
On this page
- Clerk vs Supabase Auth: what you are really choosing
- Where the session lives
- How the database learns who the user is
- What goes wrong with Clerk and Supabase together
- Clerk webhooks: a public route that must check the sender
- How to check your own setup
- Which one should you choose?
- What Keybrum tests with each, and what it does not
- Questions
- Sources
Clerk vs Supabase Auth: what you are really choosing
Most Clerk vs Supabase Auth comparisons count features: prebuilt components, organizations, price per user. Those matter. For the data your app holds, a different question matters more: once the user is signed in, how does your database learn who they are, and what happens when that link is wrong?
Supabase Auth is part of your Supabase project. The same system that signs the user in issues the token that Postgres reads, so a policy can ask for the caller's id with one function. Clerk is a separate service with its own user store. It signs the user in on its side, and your database has to be told to trust its tokens. That extra link is where Clerk setups differ, and where they break.
| Supabase Auth | Clerk | |
|---|---|---|
| Where users are stored | In the auth schema of your own Postgres database | In Clerk's service, outside your database |
| Session token | A JWT access token, one hour by default, with a single-use refresh token | A JWT session token that lasts 60 seconds, refreshed by Clerk's SDK |
| Where the browser keeps it | In the storage the Supabase client is given; cookies when you use the server-side setup | The __session cookie on your domain, plus an HttpOnly __client cookie on Clerk's Frontend API domain |
| How Postgres learns the user | auth.uid() in a policy | auth.jwt()->>'sub' in a policy, once Clerk is added as a third-party auth provider |
| Sign-up by default | Open: anyone can create an account | Open: the default mode gives broad user access |
| Getting user rows into your tables | They are already in auth.users; a trigger can copy them | Webhooks, which you must verify |
Where the session lives
Supabase Auth hands the client an access token and a refresh token. Supabase's docs describe access tokens as short lived, usually between five minutes and one hour, and say most applications should keep the default of one hour. Refresh tokens never expire and can be used once. In a server-rendered app the session sits in cookies, and the server must verify it on every request. The Supabase Auth guide explains why getClaims() is the call to use there and getSession() is not.
Clerk splits the session in two. A long-lived client token sits in the __client cookie, set on Clerk's Frontend API domain and marked HttpOnly. A short-lived session token sits in the __session cookie on your app's domain. Clerk describes its lifetime as "an extremely short session token lifetime of 60 seconds", and its SDK fetches a new one on a 50-second interval. That cookie is not HttpOnly, because Clerk's client-side SDKs must be able to read it.
What this means in practice: a stolen Supabase access token works until it expires, up to an hour by default. A stolen Clerk session token works for under a minute, but a script injected into your page can read each new one while the tab is open. In both cases cross-site scripting is the way in, so the session design does not excuse you from security headers and from escaping what users type.
How the database learns who the user is
With Supabase Auth
The Supabase client sends the user's access token with each query. Postgres switches to the authenticated role, and auth.uid() returns the user's id. A policy compares it with a column of the row. Nothing to wire.
With Clerk
Clerk and Supabase both document the same current path: add Clerk as a third-party auth provider in the Supabase dashboard, under Authentication, then pass Clerk's session token to the Supabase client through its accessToken option. Supabase's docs say its API then trusts tokens issued by the provider much as it trusts its own. Clerk's guide calls this native integration the recommended way and notes that there is no need to share your Supabase JWT secret key with Clerk.
-- Clerk ids are text. The column fills itself from the token.
create table public.tasks (
id bigint generated always as identity primary key,
name text not null,
user_id text not null default (auth.jwt()->>'sub')
);
alter table public.tasks enable row level security;
create policy "Users read their own tasks"
on public.tasks for select to authenticated
using ( (select auth.jwt()->>'sub') = user_id );
create policy "Users add their own tasks"
on public.tasks for insert to authenticated
with check ( (select auth.jwt()->>'sub') = user_id );sub is the Clerk user id. A tutorial policy built on auth.uid() and a uuid column does not fit a Clerk project.Two limits from Supabase's third-party auth page are worth knowing. After a signing key rotation at the provider, allow up to 30 minutes for Supabase to pick it up. And third-party users are billed by Supabase as third-party monthly active users, at $0.00325 each beyond your plan's quota, on top of what you pay Clerk.
What goes wrong with Clerk and Supabase together
- The policy that does not fit, so it is dropped. Policies copied from a Supabase Auth tutorial use
auth.uid(). On a Clerk project they fail, the list comes back empty, and the quick way out isusing (true)or RLS off. Every signed-in user, or every visitor, then reads every row. - The secret key shortcut. Many Clerk apps skip the integration: the server checks the Clerk session, then queries Supabase with the secret (service role) key. That key bypasses every policy, so each route must check the owner of each record itself. One forgotten check is an IDOR.
- Supabase Auth is still there. Supabase's docs state that it is not possible to disable Supabase Auth when you use a third-party provider. If sign-up is still allowed on the Supabase side, a stranger can get an
authenticatedtoken without going through Clerk. Turn off Allow new users to sign up and anonymous sign-ins in the Supabase Auth settings. - The public key is still in the bundle. Clerk does not hide your Supabase URL or publishable key. A table with RLS off is readable by anyone, signed in or not.
- Unverified webhooks. Covered below.
With Supabase Auth alone, the list is shorter and well known: open sign-up on an internal app, policies for authenticated that pass for everyone, roles read from user_metadata, and wide redirect URLs. The Supabase Auth guide covers each setting.
Clerk webhooks: a public route that must check the sender
Clerk keeps your users. If your app needs them in its own tables, to show other users' names or to store extra fields, Clerk sends webhooks such as user.created. Its docs are careful here. They say to make sure the webhook route is not protected, because incoming webhook events do not contain auth information. They also say deliveries are not guaranteed, and that syncing is eventually consistent.
A route that must accept requests from the internet without a session is a route anyone can post to. The only thing that separates Clerk from a stranger is the signature. Clerk's verifyWebhook() helper checks it with your endpoint's signing secret, stored as CLERK_WEBHOOK_SIGNING_SECRET. A handler that parses the JSON body directly will create or update a user row for whoever sends a well-shaped request. If that row carries a role or a plan, the forged event grants it.
// app/api/webhooks/clerk/route.ts
import { verifyWebhook } from "@clerk/nextjs/webhooks";
import type { NextRequest } from "next/server";
export async function POST(req: NextRequest) {
try {
const evt = await verifyWebhook(req); // throws when the signature is wrong
if (evt.type === "user.created") {
// write the row here, from evt.data only
}
return new Response("ok", { status: 200 });
} catch {
return new Response("Invalid signature", { status: 400 });
}
}Clerk's docs also suggest asking whether you need the sync at all. If what you need is in the session token, you can read it from there with strong consistency and skip the webhook.
How to check your own setup
- 1
Read your policies
Run the query below in the Supabase SQL editor. On a Clerk project, each condition should mention
auth.jwt(). On a Supabase Auth project,auth.uid(). A condition oftrueon a table with user data is a leak with either. - 2
Find the secret key in your code
Search for
service_role,SUPABASE_SERVICE_ROLE_KEYandsb_secret_. Each use is a place where policies do not apply. Confirm the route checks the session and the record's owner, and that the key is not behind aNEXT_PUBLIC_orVITE_prefix. - 3
Check who can sign up
In Clerk, look at the sign-up mode: Open, Invite-only or Waitlist. In Supabase, look at Allow new users to sign up and anonymous sign-ins. An internal tool should not be Open on either side.
- 4
Post to your own webhook without a signature
Send the request below to your own webhook route, on staging if you have one. The answer should be a 400. A 200 means the handler trusted the body.
- 5
Sign in as a second user
Create two accounts. As the second one, ask for a record that belongs to the first, by its id. It should not come back.
select tablename, policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public'
order by tablename;qual is the using condition, with_check the condition on new rows.curl -i -X POST "https://YOUR_APP/api/webhooks/clerk" \
-H "Content-Type: application/json" \
-d '{"type":"user.created","data":{"id":"user_selftest_matches_nobody"}}'Which one should you choose?
Supabase Auth is the simpler choice when your data is already in Supabase and email, social and magic link sign-in cover your needs. There is one system, one token, and policies that work with the documented examples. Fewer links means fewer places to get the link wrong.
Clerk is the better choice when sign-in itself is a product surface for you: polished prebuilt screens, organizations with roles, or a backend that is not Supabase. Its session tokens are very short lived and its sign-up modes are a clear switch. You take on the integration with your database and the webhook route. If you want to own the auth code and the user table instead, Better Auth is the library route, with its own checklist.
Neither choice writes your authorization. A provider proves identity. Your policies and your server code decide access, and that is where generated apps leak.
What Keybrum tests with each, and what it does not
Keybrum is the automated pentest we build for apps made with AI. It attacks the live app from outside, once you have proved the app is yours.
- On a Clerk app: it reads the public Clerk environment, then tries to create a throwaway account and confirm it with the emailed code, as any stranger with a mailbox would. If that works, it reports that sign-up is open to anyone and uses the account for the signed-in and two-account tests.
- On the Clerk webhook: it sends one
user.createdevent, with an id that matches nobody and no signature, to the webhook routes that name Clerk. An accepted event is a finding. - On Supabase Auth: it signs up a new account the same way, checks whether the auth redirect allow-list accepts any site, tests the project's JWT secret against known weak values, and checks sign-in for throttling and for answers that reveal which emails are registered.
- Behind either: it reads your tables with no session and as the new account, tries rolled-back inserts and updates, and tries to set
role,planorcreditson its own row.
It does not read your Clerk dashboard or your Supabase settings, so it cannot tell you that MFA is off or that an organization role is too wide. If your sign-up needs more than an emailed code, such as an invitation, it cannot create an account, and the report says the signed-in tests did not run. It never tests deletes.
A one-time report on one app is €49. Plans start at €29 a month excluding VAT and attack again on every deploy.
Questions
Is Clerk more secure than Supabase Auth?
Both handle sign-in, password storage and token signing for you, and both do it well. The difference is in the wiring: Supabase Auth is built into the database's access model, while Clerk needs an integration and often a webhook. More wiring gives more places for a mistake, but the leaks we see come from policies and server code with either one.
Can I use Clerk with Supabase row level security?
Yes. Add Clerk as a third-party auth provider in Supabase and pass the Clerk session token through the client's accessToken option. Policies then compare auth.jwt()->>'sub', the Clerk user id, with a text column on the row.
Does auth.uid() work with Clerk?
Clerk's guide does not use it. Clerk user ids are text, and the documented policies read the id from auth.jwt()->>'sub' and store it in a text column. Policies written with auth.uid() for Supabase Auth need to be rewritten.
Is the Clerk Supabase JWT template still supported?
It has been deprecated since 1 April 2025, according to both Clerk and Supabase. Supabase says it offers only limited support for it. The replacement is the third-party auth integration, which does not require sharing your Supabase JWT secret.
Do I have to verify Clerk webhooks?
Yes. Clerk's docs say the webhook route must stay unprotected because events carry no auth information, so the signature is the only proof the request comes from Clerk. Use verifyWebhook() with your endpoint's signing secret and reject anything that fails.
How long does a Clerk session token last?
Sixty seconds. Clerk's SDK requests a new one every 50 seconds while the app is open. The overall session is governed by a separate long-lived client token kept in an HttpOnly cookie on Clerk's Frontend API domain.
Sources
- 1.Integrate Supabase with Clerk, Clerk Docs
- 2.Clerk (third-party auth), Supabase Docs
- 3.Third-party auth overview, Supabase Docs
- 4.How Clerk works, Clerk Docs
- 5.Sync Clerk data to your app with webhooks, Clerk Docs
- 6.Restrictions, Clerk Docs
- 7.User sessions, Supabase Docs