From fd12f11cd747cd69c13f83b87dbdf7fbcdf0033e Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 21 Jul 2026 20:22:09 +0000 Subject: [PATCH] Fix ADMIN_PANEL_ENABLED never being read from frontend/.env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit process.env.ADMIN_PANEL_ENABLED was always undefined in the running SvelteKit server process — Vite only injects VITE_-prefixed vars into process.env for server-side code; plain vars in frontend/.env never reached it, so the admin panel stayed disabled (cog hidden, /admin/* 404s) no matter what the .env file said. Switched to SvelteKit's own $env/dynamic/private, which reads it correctly in dev, preview, and adapter-based deployments. Reproduced and verified the fix against a real frontend/.env file (not an inline shell var, which is what masked this the first time). --- frontend/src/routes/+layout.server.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/routes/+layout.server.ts b/frontend/src/routes/+layout.server.ts index 65dcf89..0ad892f 100644 --- a/frontend/src/routes/+layout.server.ts +++ b/frontend/src/routes/+layout.server.ts @@ -1,9 +1,16 @@ +import { env } from '$env/dynamic/private'; import type { LayoutServerLoad } from './$types'; // The admin panel is off by default on every deployment — it only appears (cog icon // and the /admin/* pages themselves, see admin/+layout.svelte) once this is // explicitly turned on. This is a UI-visibility gate only; the backend's API key // check on every /api/admin/* request is what actually protects it either way. +// +// Uses $env/dynamic/private rather than raw process.env — Vite does not inject +// arbitrary (non-VITE_-prefixed) .env vars into process.env for server code, so +// process.env.ADMIN_PANEL_ENABLED is always undefined here even with it set in +// frontend/.env. $env/dynamic/private is SvelteKit's own env accessor and reads it +// correctly in dev, preview, and any adapter-based deployment. export const load: LayoutServerLoad = async () => { - return { adminPanelEnabled: process.env.ADMIN_PANEL_ENABLED === 'true' }; + return { adminPanelEnabled: env.ADMIN_PANEL_ENABLED === 'true' }; };