I want to delete cookies but i got below error whenever i call remove cookie method to remove cookie. All my methods are server actions a given below. Please
Error
[Error]: Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options
Remove User Cookie server action
"use server";
import { cookies } from "next/headers";
export async function removeUserCookie(): Promise<void> {
cookies().delete({
name: "auth",
path: "/",
});
cookies().delete({
name: "user",
path: "/",
});
}
Function where cookie needs to be removed
"use server";
import { removeUserCookie } from "./logout";
export default async function validateSession(
responseStatus: number,
): Promise<void> {
if (responseStatus !== 200) {
removeUserCookie()
throw new Error(`Invalid Response: ${responseStatus}`);
}
}