Question about actions + cookies
I'm currently trying to port over our company's website from Svelte 5 -> Solid, and I wasn't sure how to replicate this picture in an action.
setCookie
needs an event to be passed in, and as far as I can tell there's no clear way to get the event. I already tried getRequestEvent
and that returned undefined, so I'm a bit stuck with how to do this. Would I have to do this in an API route only? Sveltekit also has those but I didn't have to use one for this, you just get the request and cookies in an action. Thanks.13 Replies
getRequestEvent should work.
There’s an example in the docs how to set a cookie
https://docs.solidjs.com/reference/server-utilities/get-request-event#response
it's returning undefined every single time
I'm assuming I have to do it inside an action where I use 'use server' but that gives me a different issue where trying to run the action then breaks the browser and I have to just exit the window
"use server"
So perhaps that other issue needs to be addressed first.
Full example:
https://github.com/solidjs/solid-start/blob/834f30e5db12d841f18b2c68a92b770dc2619ca4/examples/with-auth/src/lib/index.ts#L27-L47
used here
https://github.com/solidjs/solid-start/blob/834f30e5db12d841f18b2c68a92b770dc2619ca4/examples/with-auth/src/routes/login.tsx#L14GitHub
solid-start/examples/with-auth/src/routes/login.tsx at 834f30e5db12...
SolidStart, the Solid app framework. Contribute to solidjs/solid-start development by creating an account on GitHub.
GitHub
solid-start/examples/with-auth/src/lib/index.ts at 834f30e5db12d841...
SolidStart, the Solid app framework. Contribute to solidjs/solid-start development by creating an account on GitHub.
Yeah I don't know what is obviously wrong about this. But the screen freezes every time I click on the submit button and I have to exit the window.
For one you are missing the second parameter on the action; see
https://docs.solidjs.com/solid-router/reference/data-apis/action#notes-of-form-implementation-and-ssr
Yes I tried both variations - it froze either way
So this works. So there is something about either the "with"/data typing or the name of the function
Not necessarily; you haven't put "use server" in yet.
Yeah shoot never mind - still breaks
For curiosity; what's the file path?
It shouldn't make a difference but have you tried
src/routes/login.tsx
?No difference
So it seems to be my middleware is causing the issue
That's what seemed to be causing the infinite loop.