# Supabase getSession vs getUser vs getClaims: which is safe on the server?

Canonical: https://caelo.sh/guides/supabase-getsession-vs-getuser
Published: 2026-11-27 · Updated: 2026-11-27 · Arthi Arumugam, Caelo by Irth Labs

**Short answer:** On the server, never trust `getSession()`. Supabase says it reads the session out of the cookie without revalidating it, so its contents may not be authentic. Supabase's Next.js guide says to protect pages and user data with `getClaims()`, which verifies the token's signature, and to call `getUser()` when you need an up-to-date user record from the Auth server.

## The three methods, compared

| Method | What it does | Use it for |
| --- | --- | --- |
| `getSession()` | Reads the session from storage or cookies. Does not verify it. | Browser code that needs the current access token for the UI. Not for server-side decisions. |
| `getClaims()` | Verifies the JWT signature. With asymmetric signing keys this is local against the project's public keys; with a symmetric secret it calls the Auth server. | Protecting pages, route handlers and server actions. Supabase's Next.js guide says "Always use `supabase.auth.getClaims()` to protect pages and user data." |
| `getUser()` | Makes a request to Supabase Auth and returns the current user record. | When you need fresh data, for example whether the user still exists or their latest email. |

## The vulnerable pattern and the fix

Vulnerable: an admin check built on an unverified cookie

```tsx
// app/admin/page.tsx (Server Component)
const supabase = await createClient();
const { data: { session } } = await supabase.auth.getSession();
if (!session) redirect("/login");

const isAdmin = session.user.app_metadata?.role === "admin"; // not verified
```

Fixed: verify the token before you trust anything in it

```tsx
const supabase = await createClient();
const { data, error } = await supabase.auth.getClaims();
if (error || !data?.claims) redirect("/login");

const userId = data.claims.sub;
const isAdmin = data.claims.app_metadata?.role === "admin";
```

Database queries made with the user's client are still filtered by row level security, because the database checks the token itself. The risk with `getSession()` on the server is in your own logic: redirects, admin checks, and anything you do with a secret key based on who the session says the user is.

## What about Next.js middleware, now called Proxy?

Supabase's Next.js guide says: "Never trust `supabase.auth.getSession()` inside server code such as Proxy." The Proxy's job in that guide is to refresh the auth token by calling `getClaims()` and pass the refreshed cookies on. Follow the guide's `createServerClient` setup exactly, including returning the response object that `setAll` built, or the refreshed cookies never reach the browser.

## Fix it, step by step

1. Find every server-side call: `grep -rn "getSession()" app src lib middleware.ts proxy.ts`
2. In each Server Component, route handler, server action and the proxy, replace `getSession()` with `getClaims()` and read the user ID from `claims.sub`.
3. Where you need the full, current user record, call `getUser()` instead and accept the extra network request.
4. Keep `getSession()` only in browser code, where it is the documented way to read the current token.
5. Never decide anything based on `user_metadata`: users can edit their own `user_metadata`. Put roles in `app_metadata` or a table that users cannot write.

## Can a scanner catch this?

Caelo does not check auth logic, so it will not flag `getSession()` on the server. The grep above finds every call in a minute; the judgement of which ones run on the server is yours.

- [Install Caelo: npx caelo . or the MCP server](/)
- [How Caelo compares with gitleaks, TruffleHog, Semgrep and others](/compare)

## Check your own app

1. Run the free local check: `npx caelo .` Caelo is a free, open source (MIT) command line tool and MCP server from Irth Labs that checks the files of an AI-built app for exposed API keys, Supabase and Firebase misconfigurations and `.env` files with real values. It runs on your machine, uploads nothing and uses no AI model. Each finding comes with a plain-English fix.
2. Follow the fix in the report and rerun Caelo. For an untracked, unignored file containing secrets, preview the US$19 quick fix. https://caelo.sh/fix
3. For an engineer's assessment, book the US$490 App Health Check. Irth Labs delivers a report and fixed repair quote, with credit toward the repair. https://www.irthlabs.com/start?service=app-health-check

## Questions

### Why does getClaims() sometimes call the Auth server?

Supabase says that with asymmetric signing keys the JWT is verified locally against the project's JSON Web Key Set. With a symmetric JWT secret, `getClaims()` sends a request to the Auth server, like `getUser()`.

### Is getUser() slower than getClaims()?

Usually, because it always makes a network request to Supabase Auth. Use `getClaims()` for routine page protection and `getUser()` when you need the latest user record.

### Why do I see a warning that using getSession() could be insecure?

supabase-js warns when the user object from `getSession()` is used on the server, because it came from storage without verification. Switching that code to `getClaims()` or `getUser()` is the fix.

## Sources

- [Supabase docs: Setting up server-side auth for Next.js.](https://supabase.com/docs/guides/auth/server-side/nextjs)
- [Supabase reference: auth.getSession().](https://supabase.com/docs/reference/javascript/auth-getsession)
- [Supabase reference: auth.getClaims().](https://supabase.com/docs/reference/javascript/auth-getclaims)
- [Supabase docs: JWT signing keys.](https://supabase.com/docs/guides/auth/signing-keys)
- [supabase-js issue #1010: getSession warning on the server.](https://github.com/supabase/supabase-js/issues/1010)

## Related guides

- [How to check your Supabase row level security is actually working](https://caelo.sh/guides/supabase-rls-check)
- [Is my v0 app secure? A check for v0 apps on Vercel](https://caelo.sh/guides/is-my-v0-app-secure)
- [Security checklist for apps built with Lovable, Bolt, Cursor, Replit or v0](https://caelo.sh/guides/vibe-coded-app-security-checklist)
- [What does USING (true) mean in a Supabase RLS policy, and is it safe?](https://caelo.sh/guides/supabase-rls-using-true)
