Cannot set path of cookie in route handler to paths other than the path of the request
Answered
American Sable posted this in #help-forum
American SableOP
I am trying to set a path on a cookie using cookies(), but I am unable to set paths other than the path of the current request. Am I just not understanding how cookies work, or is this a bug?
// app/api/route.ts
// This will not set a cookie on the browser. Only works if I set path to '/api'
export async function GET() {
cookies().set({
name: 'cookie',
value: 'monster',
path: '/api/foo'
});
return NextResponse.json({ hello: 'world' });
}Answered by American Sable
Never mind, I guess I just don't know how cookies work in the browser. You need to be at the right path to see the cookie.
1 Reply
American SableOP
Never mind, I guess I just don't know how cookies work in the browser. You need to be at the right path to see the cookie.
Answer