Hi! I'm facing a weird behavior when trying to use 'useSession' or 'getSession' in a "use server" function. If I clear the cookies on the page, I get the error "Cannot set headers after they are sent to the client".
To reproduce: clone and run https://github.com/livyk/solid-bug (it's a starter with the tailwind template + the sessions example from the docs). Navigate to /users. Clean cookies on the page and you are supposed to get the error.
Am I doing something wrong, or it's a potential bug?
Thanks!
#Using session causes "Cannot set headers after they are sent to the client"
5 messages · Page 1 of 1 (latest)
-
useSession()will always create a session if there isn't one already. UsegetCookie()instead. -
That error typically appears when you try to modify cookies (session, headers) when Start has already started streaming the response (which is the default). Either the session is being modified in the wrong place or you need to add
{ deferStream: true }to thecreateAsync()involved.
Thank you for the answer! Then I'll try to solve it using deferStream or just make a custom session using getCookie.
Adding { deferStream: true } helped!
The session example should be updated with { deferStream: true }
Thank you again!
some months later seconding that thank you as this was what I was looking for ❤️