Question about Session Cookies (Cloudflare Worker) #2434
-
Hi all, I am using hono-sessions from https://github.com/jcs224/hono_sessions For this code snippet:
How can I pass the SESSION_ENCRYPTION_KEY? It is coming from an env. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
something like this app.use('*', async (c, next) => sessionMiddleware({
store,
encryptionKey: c.env.SESSION_ENCRYPTION_KEY,
expireAfterSeconds: 900,
cookieOptions: {
sameSite: 'Lax',
path: '/',
httpOnly: true,
},
})) |
Beta Was this translation helpful? Give feedback.
-
Here is an example from the docs https://hono.dev/getting-started/cloudflare-workers#using-variables-in-middleware |
Beta Was this translation helpful? Give feedback.
-
For CF, i guess it expects you to save env variables in |
Beta Was this translation helpful? Give feedback.
-
I manage to solve this by using the following:
Then in my cookieSessionMiddleware:
|
Beta Was this translation helpful? Give feedback.
If you wrap it like this, you won't have to worry about types
You can also add
<{ Bindings: Env}>
if need tocreateMiddleware