Hi, i have been trying to delete a cookie and have made a route handler for it. accessing cookiestore just returns empty cookie object/array. No value or anything
export async function POST(req: Request) {
return await apiHandler(async () => {
const { sessionCookie }: { sessionCookie: string } = await req.json();
const cookieStore = cookies();
console.log(cookieStore.size); // returns undefined
// const cookie = cookieStore.get(sessionCookie);
// console.log(cookie); // also returns undefined
cookieStore.delete(sessionCookie); // does nothing
console.log("deleted!");
return NextResponse.json({
status: 201,
body: "Your session has been deleted!",
});
});
}
the controller that fetches the route
export const deleteCookie = async (sessionCookie: string) => {
return await fetchHandler<string>(async () => {
return await fetch(`${hostURL}/api/cookie`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
sessionCookie: sessionCookie,
}),
});
});
};
been trying to delete session cookie to handle one edge case.