#Question about actions + cookies

16 messages · Page 1 of 1 (latest)

mossy swan
#

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.

whole solar
mossy swan
#

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

leaden widget
#
const myAction = action(async (data: FormData) => {
  'use server';
  const event = getRequestEvent();
  // `event` should not be undefined here

  // … rest …
}, 'my-action');

"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#L14

GitHub

SolidStart, the Solid app framework. Contribute to solidjs/solid-start development by creating an account on GitHub.

GitHub

SolidStart, the Solid app framework. Contribute to solidjs/solid-start development by creating an account on GitHub.

mossy swan
#

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.

mossy swan
#

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

leaden widget
#

Not necessarily; you haven't put "use server" in yet.

mossy swan
#

Yeah shoot never mind - still breaks

leaden widget
#

For curiosity; what's the file path?

mossy swan
leaden widget
#

It shouldn't make a difference but have you tried src/routes/login.tsx?

mossy swan
#

No difference

mossy swan
#

So it seems to be my middleware is causing the issue