InterviewBuddy
All interview questions

Why should secrets stay in server code?

Intermediate

Answer

Values exposed through NEXT_PUBLIC_ are bundled for the browser. Server-only environment variables can remain private when referenced only by server code.

Explanation

A publishable Supabase key is designed for clients when RLS is correct. A service-role key bypasses RLS and must never enter browser code.

Example

NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY: browser-safe; service-role key: server only