solid-start
solid-start copied to clipboard
[Bug?]: Session cookie set yet session data is empty
Duplicates
- [x] I have searched the existing issues
Latest version
- [x] I have tested the latest version
Current behavior 😯
It seems like there might be a bug where the session cookie is set, shows in the browser, is sent to the server (tested by having a middleware get the cookie and print to the terminal) but the session library/module does not recognize/can't fetch/parse it.
Expected behavior 🤔
The session data should have information about the session.
Steps to reproduce 🕹
This is how the session config looks:
const sessionConfig: SessionConfig = {
password: "password-goes-here", // Ensure this is consistent across environments
name: "auth",
maxAge: 60 * 60 * 24 * 7, // 7 days
cookie: {
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
httpOnly: true,
},
};
The middleware I used to verify if the cookie was sent by the browser:
import { createMiddleware } from "@solidjs/start/middleware";
import { parse } from "cookie";
export default createMiddleware({
onRequest: (event) => {
const cookieHeader = event.request.headers.get("cookie");
if (cookieHeader) {
const cookies = parse(cookieHeader);
let authToken = cookies["auth"] || null;
console.log("Auth Token:", authToken);
} else {
}
},
});
Context 🔦
Trying to use the session for auth.
Your environment 🌎
Runtime: bun