Supabase SSR
Supabase client library optimized for server-side rendering frameworks.
3. Used by agents' projects
Dependency in 286 public GitHub projects set up for AI coding agents that we scanned (4.6%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
supabase.com/llms.txtFrom the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What Supabase SSR does
Supabase SSR always keeps the Supabase auth session in cookies, which the README calls "the entire point of the package", so a server-rendered request reads the same session the browser wrote.
Supabase SSR popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Supabase SSR is used
- Supabase SSR is a dependency in 286 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (5.9% of the 4,867 JavaScript/TypeScript ones), #2 of 287 in sdks for hosted services.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 564; those are left out of every share on this page.
- Projects that use it most often also use Supabase JS (97.9%), Next.js (93.7%), Lucide React (82.9%).
- It is more common in projects set up for Roo Code (6.3%) than for OpenCode (2.6%).
By coding agent
Often used with
Supabase SSR in practice
Strengths
The session lives in cookies, so a server-rendered page sees the same logged-in user as the browser. The README says this is why the package exists.
The maintainers write that the Next.js, React, Remix and SvelteKit auth-helpers are deprecated and "consolidated into <code>@supabase/ssr</code> for better maintenance and consistency."
The README's overview describes the package as "a framework-agnostic way" to use the Supabase JavaScript library in SSR frameworks.
The README gives complete middleware code. It builds the server client with <code>parseCookieHeader</code>, calls <code>getClaims()</code> "before any route code runs", and appends each queued cookie as <code>Set-Cookie</code> with <code>serializeCookieHeader</code>.
Watch out for
The README says passing <code>auth.storage</code> has no effect, and a one-time console warning is logged. The exception is <code>auth.userStorage</code>, which is still respected when <code>cookies.encode</code> is set to <code>"tokens-only"</code>.
If the server never needs the session, the README points to <code>createClient</code> from <code>@supabase/supabase-js</code> with your own <code>storage</code>. It says there is "no reason" to use <code>@supabase/ssr</code> in that case.
Supabase refresh tokens are single-use. If two requests arrive at the same moment with the same expired cookie, such as two tabs opening together, the second refresh fails and that request gets <code>session: null</code>. The README says middleware mitigates this "for the common case". Parallel client <code>fetch()</code> calls still need to handle <code>null</code> sessions and retry or re-authenticate.
React Router middleware: refresh the session before any route code runs
export const supabaseMiddleware: MiddlewareFunction<Response> = async (
{ request, context }, next,
) => {
const pendingCookies: PendingCookie[] = [];
const pendingHeaders: Record<string, string> = {};
const supabase = createServerClient(
process.env.SUPABASE_URL!,
process.env.SUPABASE_PUBLISHABLE_KEY!,
{
cookies: {
getAll() {
return parseCookieHeader(request.headers.get("Cookie") ?? "");
},
setAll(cookiesToSet, headers) {
pendingCookies.push(...cookiesToSet);
Object.assign(pendingHeaders, headers);
},
},
},
);
// Trigger lazy session init / refresh before any route code runs.
await supabase.auth.getClaims();
context.set(supabaseContext, supabase);
const response = await next();
for (const { name, value, options } of pendingCookies) {
response.headers.append(
"Set-Cookie",
serializeCookieHeader(name, value, options),
);
}
for (const [key, value] of Object.entries(pendingHeaders)) {
response.headers.set(key, value);
}
return response;
};More about Supabase SSR
Funding
- GitHub Sponsors: https://github.com/supabase
- 18 GitHub sponsors
Packages around it
- @supabase/supabase-js: Core Supabase client
- next: React framework
- lucide-react: Icon set
- clsx: Class name joiner
- tailwind-merge: Tailwind class merging
- class-variance-authority: Component variants
More in SDKs for hosted services
Alternatives
Supabase SSR This page
Get started
Install it.
npm install @supabase/ssrRules for your agent
## Supabase SSR
- Use `@supabase/ssr` only when server code needs the session. For browser-only session handling, use `createClient` from `@supabase/supabase-js` with your own `storage`.
- Do not add `@supabase/auth-helpers-nextjs`, `-react`, `-remix` or `-sveltekit`. The README lists them as deprecated; depend on `@supabase/ssr` directly.
- Do not pass `auth.storage` to `createBrowserClient` or `createServerClient`. It has no effect and logs a warning. `auth.userStorage` is respected only when `cookies.encode` is `"tokens-only"`.
- Follow the README's middleware example. Give `createServerClient` a `cookies.getAll` that parses the request's `Cookie` header with `parseCookieHeader`. Add a `cookies.setAll` that queues cookies and headers. Append each queued cookie with `serializeCookieHeader` as `Set-Cookie` and set the queued headers on the response.
- Refresh the session once per request in middleware with `await supabase.auth.getClaims()` before loaders and actions run.
- When parallel client requests may race to refresh the same expired token, handle `session: null` and retry or re-authenticate.
- For choosing between `getSession()`, `getUser()` and `getClaims()`, follow the official guides at https://supabase.com/docs/guides/auth/server-side.