Session: Cannot read properties of undefined (reading 'session')
joshamaju opened this issue · comments
The session module throws TypeError: Cannot read properties of undefined (reading 'session')
at point of registering the middleware
app.use(
session({
// Session store
store: new SimpleCookieStore(),
// Default session data when a new session is created.
// It can be a function.
// It is shallow cloned, if you need a deep clone, use a function.
defaultSessionData: {},
})
);
Thank you for reporting. Turns out it's not a bug but a serious documentation issue 😅
The session middleware requires the cookie middleware to be inserted before it or getSessionId
option to be set for custom behavior. I updated the docs accordingly.
Btw I noticed that you're using Hattip as an Express middleware which is supported but it only makes sense if you have a hard requirement to use Express for some other reason. You can just use createServer
instead of createMiddleware
and get rid of Express entirely if you don't have such a requirement:
createServer(router.buildHandler()).listen(3000, "localhost", () => {
console.log("Server listening on http://localhost:3000");
});
That fixed it. Thanks