If your Sanity API token is exposed in a Next.js site, anyone who opens DevTools can read it and use it against your project. This is more common than it should be on inherited codebases, and the fix is quick once you know where to look. This post covers how to confirm the leak, what it can cost you, and the order I'd fix it in.
How a Sanity API token ends up exposed
Three patterns cause almost every case I see on sites built by someone else:
A NEXT_PUBLIC_ prefix on the token. Next.js inlines any variable with that prefix into the browser bundle at build time. A developer adds it to make a client component work, and the token ships to every visitor.
A token in a client component or a shared client file. Even without the prefix, a Sanity client created with a token inside a file imported by a use client component can drag the value into the bundle.
A token committed to git.…