Fix ADMIN_PANEL_ENABLED never being read from frontend/.env
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).
This commit is contained in:
@@ -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' };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user