setCookie not working in _middleware
Closed this issue · 1 comments
Amber-Williams commented
setCookie
seems to work fine when used in a Nextjs api route, but in Next's latest released _middleware
file doesn't work.
This can be reproduced my creating a _middleware.ts
file with the following
import type { NextRequest } from "next/server"
import { NextResponse } from "next/server"
import { setCookie } from "nookies"
const AuthMiddleware = async (req: NextRequest) => {
let res = NextResponse.next()
setCookie({ res }, "test", "test value", {
path: "/",
})
return res
}
However using the NextResponse res.cookie("test", "test value")
works. Unfortunately that method it doesn't play well with Typescript for options
stale commented
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.