All guidesSupabase RLS and keys

Supabase question

What is the Supabase anon key, and where do I find it?

By Ohad Krispin, founder of VibeRaven · LinkedIn

Short answer

Open your Supabase project → Settings → API Keys and copy the legacy key labeled anon. For new frontend code, open Connect and copy the publishable key (sb_publishable_). Database grants and Row Level Security control what either public key can read or change.

Use this from your agent
  • Claude Code: 7 read-only tools; public repos only.
    claude mcp add --transport http viberaven https://viberaven.dev/mcp
  • Codex: same server, from the Codex CLI.
    codex mcp add viberaven --url https://viberaven.dev/mcp
  • In your repo: writes Vercel + Supabase check rules for your agent (what it writes).
    npx -y viberaven init
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.

Terminal output of npx viberaven check flagging a Supabase table created without RLS in a migration file, the kind of table the anon key may reach, depending on its grants.
Terminal output of npx viberaven check flagging a Supabase table created without RLS in a migration file, the kind of table the anon key may reach, depending on its grants.
On this page

Find the variable your frontend already uses

Search the tracked source for the variable name. Use the public key from the same project as the URL. If this search turns up a public-prefixed admin variable, check where the service role key belongs.

Terminal
git grep -l -E "VITE_SUPABASE_(ANON|PUBLISHABLE)_KEY|NEXT_PUBLIC_SUPABASE_(ANON|PUBLISHABLE)_KEY"

What is the anon key in Supabase?

The anon key is your project's public API key, and Supabase lists it as the "Legacy version of publishable keys". A request with it runs as the anon Postgres role when nobody is signed in, and as authenticated when it carries a signed-in user's token, so Supabase says to write Row Level Security policies "for the anon and authenticated roles". The name comes from that anon role. It is not an anonymous sign-in, which creates a real user with the authenticated role.

It is meant to be public: Supabase calls the publishable key "Safe to expose online", source code included. Your grants and RLS decide what it can reach.

Whether that is safe for your tables is a separate question: the grants and RLS checks for the anon key.

Supabase lists legacy-key deprecation for early 2027. See the API keys guide for the current timing.

SUPABASE_ANON_KEY: which variable holds it?

In your frontend, the anon key goes in the env variable your client reads, with your framework's public prefix: NEXT_PUBLIC_SUPABASE_ANON_KEY in Next.js, VITE_SUPABASE_ANON_KEY in Vite. Supabase's own examples now use the publishable key under NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY.

In Supabase Edge Functions, SUPABASE_ANON_KEY is set for you. Supabase says SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY "still exist in the runtime, but they carry the legacy keys".

How do I use the Supabase anon key in Vite?

For a new app, Supabase recommends a publishable key. Put the project URL and public key in .env.local beside package.json. Its React quickstart uses these names:

An older app may read VITE_SUPABASE_ANON_KEY instead; the anon key and the publishable key do the same job. Keep the variable name your client actually reads, or update the code and env name together. The name does not make a key secret: VITE_ values ship to the browser. Never put a service_role or sb_secret_ value there.

Environment
# .env.local, beside package.json
VITE_SUPABASE_URL=https://YOUR_PROJECT.supabase.co
VITE_SUPABASE_PUBLISHABLE_KEY=sb_publishable_REPLACE_ME

Read the same variable in your Supabase client

Use import.meta.env in Vite browser code. This example expects the publishable-key name above; an existing client using the anon-key name must read that exact name instead. Replace the placeholder with your own public key before running it.

Code
import { createClient } from '@supabase/supabase-js';

const url = import.meta.env.VITE_SUPABASE_URL;
const key = import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY;

if (!url || !key) {
  throw new Error('Missing Supabase URL or public key: check .env.local names.');
}

export const supabase = createClient(url, key);

Why is VITE_SUPABASE_ANON_KEY undefined?

Check for a missing value or a name mismatch first. Setting VITE_SUPABASE_ANON_KEY does not populate VITE_SUPABASE_PUBLISHABLE_KEY, or the other way round. Check the env file for the mode you build, and restart the Vite dev server after editing it. Production values are baked into the build, so changing a dashboard variable needs a new build and deployment.

Check whether a value exists without logging the key itself. A working client constructor still does not prove that a database request or RLS policy works.

Output
console.table({
  hasProjectUrl: Boolean(import.meta.env.VITE_SUPABASE_URL),
  hasPublicKey: Boolean(import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY),
  mode: import.meta.env.MODE,
});

Where to find the anon key and the publishable key

  1. 1
    Open your project in the Supabase Dashboard, then Settings > API Keys. Supabase says "Every key lives there, legacy or not, and there is no separate Settings > API page", so a tutorial that sends you to Settings > API and "Project API keys" is out of date.
  2. 2
    For the publishable key, select the Publishable and secret API keys tab, or open the Connect dialog. Supabase says Connect "shows the URL and publishable key for the framework you select, ready to paste into .env".
  3. 3
    No publishable key yet? Supabase says that if you see a Create new API keys button, "your project is still on legacy keys only". Creating them is safe: the new keys are added alongside the anon key without affecting it, and the anon key keeps working until you disable the legacy keys there.
  4. 4
    Put it in the frontend env file with your framework's public prefix, next to the project URL from the same project. For example:
    Environment
    # Next.js
    NEXT_PUBLIC_SUPABASE_URL=https://<project-ref>.supabase.co
    NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJ...
    
    # Vite
    VITE_SUPABASE_URL=https://<project-ref>.supabase.co
    VITE_SUPABASE_ANON_KEY=eyJ...
  5. 5
    Do not copy the key next to it by mistake. The legacy service_role key also starts with eyJ, and it and the secret keys (sb_secret_) bypass RLS, so they stay on the server.

Where the anon key and the publishable key show up

The dashboard is one of five places that hand you a public key. Which one you need depends on where the code runs. The second block is optional, for reviewing an existing app once the key is in place.

Five places, and what each gives you

The same section also holds the service_role key, which starts with eyJ too. Decode the middle part of a JWT, which is base64 JSON, and read its role field: anon is the public key, service_role is not.

Where to get the Supabase anon key or publishable key, and what each place is for
Where you lookWhat you getFor
Dashboard: Settings > API KeysThe legacy anon key (eyJ). The Publishable and secret API keys tab has sb_publishable_ keys, or a Create new API keys button if the project has only legacy keysA hosted project
Dashboard: the Connect dialogThe project URL and publishable key for the framework you pick, ready to paste into .envA new frontend
supabase projects api-keys --project-ref <your-project-ref>Every key of a hosted project, in the terminalScripts and terminals
supabase statusThe keys of the local stack started with supabase startA local stack
Edge Functions runtimeSUPABASE_ANON_KEY with the legacy key, SUPABASE_PUBLISHABLE_KEYS with the new ones, already setCode in an Edge Function: there is nothing to copy

Read the Skill, then check the relevant repository findings

Read the linked Skill and use the parts relevant to your task. From your app folder, with Node.js 20 or newer, run the command below. No global Skill installation is required for this one-off check. It writes findings under .viberaven/. Exit code 1 means blockers were found, not necessarily that the command failed; inspect the output.

Read .viberaven/agent-tasklist.md and .viberaven/gate-result.json. Check each finding against the actual code, make the smallest authorized fix, then rerun the same command and your project checks. Report the changed files, remaining findings and checks you could not perform. Keep keys and private data out of chat.

This is a repository check, not a live database test. It cannot confirm deployed grants, rotate a key or verify hosted environment values. A clear result is not proof that the app is secure. Test the affected app behavior separately; provider changes and deployment follow your normal approval process.

Terminal
npx -y viberaven@1.20.2 check

Need to fix this in your existing app?

If the diagnosis points to a variable-name mismatch, ask for that one client-setup change. Then rebuild and repeat the failing action. Do not paste real keys into the request.

Sign in to the VibeRaven website with Google and connect the app folder on your computer, with Node.js 20 or newer. Keep the connection terminal open. Claude Code, Codex or Gemini CLI must be installed and signed in. The agent uses your own provider account, and usage may be billed there.

The website sends the code change to your agent on your computer. Repository checks are advice, not a gate, and not a live database test. Review the diff, project checks and running app before keeping it. This does not read your hosted keys, change provider settings or deploy for you.

Connect my existing app

Check connection prerequisites

Review a change before keeping it

Official docs behind this checklist

FAQ for builders before launch

Should I copy the anon key or the publishable key?

Use the publishable key (sb_publishable_) for new code. Supabase supports both while you migrate and documents deprecation of the legacy keys for early 2027.

Where did Settings > API and "Project API keys" go?

Supabase now lists every key, legacy or not, under Settings > API Keys, and says there is no separate Settings > API page for them. Guides and AI answers that send you to Settings > API and a "Project API keys" box were written for the older dashboard.