ciscoheat / sveltekit-superforms

Making SvelteKit forms a pleasure to use!
https://superforms.rocks
MIT License
2.14k stars 64 forks source link

Error on forms with redirect #26

Closed stefandevo closed 1 year ago

stefandevo commented 1 year ago

Hi,

I have a login form, where I use the superforms component. When I execute the login action on the server, I do something like if (callResponse.requestId) throw redirect(302, '/auth/verify/' + callResponse.requestId); to go to a next page with a request id.

This works, however, I now see following error appearing:

Uncaught (in promise) Error: No form data found in $page.data (PageData). Make sure you return { form } in the form actions and load function.

Any idea what I should do...

ciscoheat commented 1 year ago

That must have been introduced with the multiple forms support. I'll try to release a fix later today.

ciscoheat commented 1 year ago

Are you redirecting in an endpoint or in a form action?

stefandevo commented 1 year ago

In a form action

ciscoheat commented 1 year ago

Great, it's fixed now in the latest version. If you'd been throwing a redirect in an endpoint it wouldn't work, since superForm expects an ActionResult. In that case you have to use the actionResult helper instead, described here.

ciscoheat commented 1 year ago

Is this working for you now?