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.
#Question about actions + cookies
16 messages · Page 1 of 1 (latest)
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
const myAction = action(async (data: FormData) => {
'use server';
const event = getRequestEvent();
// `event` should not be undefined here
// … rest …
}, 'my-action');
So perhaps that other issue needs to be addressed first.
used here
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