Skip to content

Creating cookie in API route handler #76748

Answered by icyJoseph
amirmasoodi asked this question in Help
Discussion options

You must be logged in to vote

Right, here you have two different HTTP requests. Within your server action, you have scope to set the cookie back to the browser, however, you "fork", a new HTTP request, to your API route/Router handler, where you set cookies, but that'd be setting the cookies on the request that was forked, not the request that started from the browser.

You are just collecting the json body payload, of the forked request, dropping the Set-Cookie header it might have had, and terminating the request. You'd need to collect the Set-Cookie from the forked response, and the append that to what you send down... or, could you... just do this?

⚠️⚠️⚠️ Not Recommended, this will make TS fight you ⚠️⚠️
    // Sen…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@amirmasoodi
Comment options

@icyJoseph
Comment options

Answer selected by amirmasoodi
@icyJoseph
Comment options

@icyJoseph
Comment options

@amirmasoodi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants