Setting cookies retrieved from an external api in a form action #8564
Replies: 2 comments 1 reply
-
Very good question, unless I'm missing something. Cookie pass-through is fully automatic in the request direction, whereas the response requires manual fiddling as you describe. Is there a better way? |
Beta Was this translation helpful? Give feedback.
-
Is there maybe some better approach by now? You can use
So I will expect that I can do something like |
Beta Was this translation helpful? Give feedback.
-
Asked this on Discord as well and figured something out.
But opening a discussion anyway as I am not sure this is a good approach and if I am missing something. Also think this is not an uncommon thing to try to do so some centralized place for it will do no harm.
I have a form action that calls an external API, this external API responds with some data and sets cookies.
The question now is: how do I pass those cookies to the client ?
Base code:
A "solution" I came up with is to(with the use of set-cookie-parser) grab the
set-cookie
headers from the fetch result and usecookies.set
to add them to my own response:But this somehow feels 'dirty' and leaves me with the strange feeling I am doing something wrong.
I also tried using setHeaders like this
but this crashes SvelteKit with a message to use
event.cookies.set
instead :(Beta Was this translation helpful? Give feedback.
All reactions