Pass external backend cookie to nextjs.
Answered
Siamese Crocodile posted this in #help-forum
Siamese CrocodileOP
Hi. I am sending requests using server actions to an external backend that sets a cookie. How can I "transfer" this cookie and set it on nextjs server? Should I use an external cookie parsing library, read all and set it using
cookies()?Answered by joulev
yes. typically if you also have control over the backend, it's recommended to send the token in a more straightforward way, e.g. as a field in the response json. but if you don't want to change the backend then read the
set-cookie header of the response, parse it and then use cookies() to set it2 Replies
@Siamese Crocodile Hi. I am sending requests using server actions to an external backend that sets a cookie. How can I "transfer" this cookie and set it on nextjs server? Should I use an external cookie parsing library, read all and set it using `cookies()`?
yes. typically if you also have control over the backend, it's recommended to send the token in a more straightforward way, e.g. as a field in the response json. but if you don't want to change the backend then read the
set-cookie header of the response, parse it and then use cookies() to set itAnswer
Siamese CrocodileOP
Sure, thank you @joulev