Next.js Discord

Discord Forum

Setting cookies in API route handlers doesn't work

Answered
Balinese posted this in #help-forum
Open in Discord
BalineseOP
I'm having trouble trying to set cookies for my tokens received from a custom server (FastAPI). The response payload seems to be getting through but cookies().set() just doesn't work. I've also tried using res.cookies.set(), doesn't work either. Am I doing something wrong here?
Answered by Balinese
I had to manually pass in the headers to the NextResponse since I'm using middleware because the Set-Cookie header was required to perform the cookies setting.
View full answer

2 Replies

BalineseOP
Up
BalineseOP
I had to manually pass in the headers to the NextResponse since I'm using middleware because the Set-Cookie header was required to perform the cookies setting.
Answer