NextResponse Set-Cookie multiple keys
Unanswered
Nile Crocodile posted this in #help-forum
Nile CrocodileOP
Nextjs is struggling because it cannot put multiple set-cookies in the header
The object has only one key, but the setCookie must be able to define multiple keys
I want to know how to do that
The object has only one key, but the setCookie must be able to define multiple keys
I want to know how to do that
return NextResponse.redirect(url, {
headers: {
'Set-Cookie': res.headers.getSetCookie()[0],
'Set-Cookie': res2.headers.getSetCookie[0],
},
})1 Reply
@Nile Crocodile Nextjs is struggling because it cannot put multiple set-cookies in the header
The object has only one key, but the setCookie must be able to define multiple keys
I want to know how to do that
return NextResponse.redirect(url, {
headers: {
'Set-Cookie': res.headers.getSetCookie()[0],
'Set-Cookie': res2.headers.getSetCookie[0],
},
})
If you want to manually construct the Set-Cookie header, then you have to follow the specifications of the cookie string.
But why bother with all of that? Just use cookies().set() https://nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options
But why bother with all of that? Just use cookies().set() https://nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options