NEXT_PUBLIC_ and VITE_ mean public: keep secrets out of them
Moving a key out of your code and into an environment variable feels safe. But in Next.js, any variable whose name starts with NEXT_PUBLIC_ is baked into the JavaScript every visitor downloads. Vite does the same with VITE_. Anyone can open the browser's developer tools and read it.
Those prefixes are fine for values meant to be public, like a Supabase URL or anon key. They're not fine for a Stripe secret key, an OpenAI key or a Supabase service_role key.
The fix: rename secret variables without the prefix, use them only in server code (API routes, server actions or edge functions), and have the browser call that server code instead. Then rotate any key that was ever public.
Want to check what your live app exposes? Run the free scan at leakyvibe.com/?demo=1&ref=blog-public-env-var-prefixes-ship-to-the-browser. It takes about 15 seconds.