pixelmund / svelte-kit-cookie-session

⚒️ Encrypted "stateless" cookie sessions for SvelteKit
MIT License
182 stars 11 forks source link

Can't build when using env var as secret #50

Closed muckelba closed 1 year ago

muckelba commented 1 year ago

Hi,

i'm trying to build my svelte app with the node adapter, but it errors, because i want to set the session secret via an environment variable when launching the server:

src/hooks.server.js:

import { handleSession } from 'svelte-kit-cookie-session';
import { env } from '$env/dynamic/private';

const sessionSecret = env.VITE_SESSION_SECRET

export const handle = handleSession({
    secret: sessionSecret
});

Error when running npm run build:

Error: Please provide at least one secret
    at normalizeConfig (file:///redacted/node_modules/svelte-kit-cookie-session/utils.js:12:15)
    at new CookieSession (file:///redacted/node_modules/svelte-kit-cookie-session/core.js:14:24)
    at Object.handle (file:///redacted/node_modules/svelte-kit-cookie-session/handle.js:4:25)
    at respond (file:///redacted/.svelte-kit/output/server/index.js:2205:42)
    at async visit (file:///redacted/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:190:20)

Is it possible to fix that or do i have to think about a different way where i dont have to build the app with a hardcoded sessionsecret?

muckelba commented 1 year ago

Okay, nevermind it's working. Forgot to exclude this file from prerendering.

muckelba commented 1 year ago

I'm sorry, the issue is not fixed. I had an .env in my project while building the app, that's why it was working. But after i renamed it, i was'nt able to build again.

pixelmund commented 1 year ago

I can't reproduce your issue, if you provide a minimal reproduction i'll reopen it!