zing
zing17mo ago

Fresh pattern help

Could anyone possibly help guide me to understand the 'freshest' pattern for the following, please? When a user hits / I load a login page, and once he submits the form, the server generates some session data in the POST handler for /, and then redirects(send back a 303) to /chat. There is an island on /chat which needs to contain the session data. How would I redirect from the form POST handler, to the /chat page and make sure that my state is passed to the island? In react or similar I would handle the 'form submission' in javascript and cache the returned session data before redirecting to /chat. Since fresh seems to promote the use of native forms I'm trying to learn how I would handle this situation. I'm thinking of setting a cookie in the redirect, to then be sent with the /chat GET, which I can use to return the page with session data inside. Is that common? Thanks!
6 Replies
ioB
ioB17mo ago
Using a cookie is probably the right thing to do.
zing
zingOP17mo ago
Thanks. I'll think about that. I suppose another way would be to set the form to POST directly to /chat, and then have a POST handler there that does a ctx.render(). Not sure about the downsides to either of these yet.
NeTT
NeTT17mo ago
of course a refresh will reset the state unless you use a cookie/localStorage
zing
zingOP17mo ago
100%. Would need to persist it somehow in the island the first time the page loads. The cookie route seems cleaner in this case. Although I am trying to get my head around the possibilities because this is quite a common use case if I'm not mistaken. Submit form -> load new page with data from the the form.
porridgewithraisins
do it the cookie way
zing
zingOP17mo ago
thanks 👍