You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] dotenv fails to load backend env when auth/db run inside SvelteKit SSR. #651
While running the SvelteKit dev server (apps/web), I call auth.api.getSession from hooks.server.ts. The @project/auth package imports @project/db, which only reads from process.env without explicitly loading the env file. Because the SSR process runs with cwd = apps/web, dotenv only sees the frontend .env, so DATABASE_URL and DATABASE_AUTH_TOKEN remain empty. As a result, the database connection fails and the dev page returns HTTP 500.
Context
Monorepo Structure:
Backend: apps/server
Frontend (SvelteKit): apps/web
Environment Variables:
Backend credentials (DATABASE_URL, DATABASE_AUTH_TOKEN, etc.) are stored in apps/server/.env
Database URL: Not set
Database Auth Token: Not set
LibsqlError: URL_INVALID: The URL '' is not in a valid format
Error: Missing API key. Pass it to the constructor `new SomeService("key")`
Visiting http://localhost:5173 returns a 500 error.
Current Workaround
Add import "dotenv/config"; to packages/db/src/index.ts, then duplicate the backend credentials (DATABASE_URL, DATABASE_AUTH_TOKEN, etc.) into apps/web/.env.
Issue: Secrets are now duplicated across two env files.
Suggested Fix
Provide a shared helper so the auth/db packages always load the backend .env even when executed inside the frontend SSR process, or document that developers must keep the env variables in apps/server/.env and apps/web/.env in sync during development.
So, for now, is the best workaround to perform all data fetching on the client side?
Once this is supported or fixed, will I be able to update my current project, or will I need to start over with a new one using bun create better-t-stack@latest?
FYI: I opened a consolidated Cloudflare env injection proposal that references this issue and suggests a root .dev.vars + explicit Wrangler bindings flow: #787
SvelteKit runs auth and the database in its own server with --backend self (#1025), and dotenv was replaced by Varlock (#1224), so shared packages now get their env from the app. If you still see this on the latest version, please reopen or open a new issue with the details.
Activity
AmanVarshney01 commentedon Oct 25, 2025
Sveltekit SSR is not supported yet
Will add this soon
az-ka commentedon Oct 25, 2025
Got it, thanks for the confirmation.
bun create better-t-stack@latest?jroth1111 commentedon Jan 2, 2026
FYI: I opened a consolidated Cloudflare env injection proposal that references this issue and suggests a root .dev.vars + explicit Wrangler bindings flow: #787
AmanVarshney01 commentedon Oct 21, 2026
SvelteKit runs auth and the database in its own server with
--backend self(#1025), and dotenv was replaced by Varlock (#1224), so shared packages now get their env from the app. If you still see this on the latest version, please reopen or open a new issue with the details.