Setting cookies with options in Next 14 middleware
Unanswered
Singapura posted this in #help-forum
SingapuraOP
I'm attempting to use
will work based on the docs here https://nextjs.org/docs/pages/api-reference/functions/next-response#setname-value. This was originally done in an Express middleware on a custom server, which I'm trying to get rid of.
It seems that the way cookies are handled has changed somewhat from Next 14 -> 15 and between Pages Router -> App Router. I'm using the pages router.
NextRequest & NextResponse to read/set cookies on a couple of routes in middleware. It's unclear to me whether setting cookies using options i.e.: const response = NextResponse.next()
response.cookies.set(COOKIES.USER_ID, '', { expires: new Date(0), httpOnly: true })will work based on the docs here https://nextjs.org/docs/pages/api-reference/functions/next-response#setname-value. This was originally done in an Express middleware on a custom server, which I'm trying to get rid of.
It seems that the way cookies are handled has changed somewhat from Next 14 -> 15 and between Pages Router -> App Router. I'm using the pages router.