VERCEL ERRORS

Supabase sb_secret returns 401: browser keys versus server keys

A Supabase secret key returns 401 when sent from a browser. Use a publishable key in client code and keep elevated access on an authenticated server.

401 Unauthorized with sb_secret_

A browser 401 may be intentional

Supabase rejects secret keys in browser requests using the User-Agent header. This does not make an exposed secret safe: another client may still use it. Secret keys have elevated database access and must stay on the server.

Checks in order

  1. Find where the request originates: browser, your server, or an Edge Function. Identify the failing URL and response before changing permissions.
  2. Use a publishable key with the signed-in user session in browser code. Keep Row Level Security policies enabled.
  3. Move privileged operations to an authenticated server endpoint and authorize the operation there. Never place a secret key in NEXT_PUBLIC_ or VITE_ variables.
  4. If a secret reached a client bundle or public log, remove the exposure and rotate that key. Rebuild the affected deployment.

Not every 401 has this cause

A missing or expired user session and an invalid project key are separate issues. Do not treat a new secret key as a user JWT, or disable authentication to hide the error.

Confirm the boundary

Inspect the built browser bundle and network requests for accidental secret exposure, then test with both an authorized and an unauthorized user.

What a DeployDoctor scan can check

A repository scan can flag visible configuration risks. It cannot inspect dashboard settings, private credentials, DNS propagation or live service responses. Confirm the result in the deployed environment.

Sources

Documentation last checked 2026-11-15. Vercel can change its documentation; confirm against the linked pages.