how can I delete a cookie on the client side in Next.JS app router
Unanswered
Seppala Siberian Sleddog posted this in #help-forum
Seppala Siberian SleddogOP
I want to delete, manipulate cookies on the client side how can I achieve that in Next.JS app router
3 Replies
You cannot directly delete a cookie, but you can overwrite it and set its expiration date to a past date, effectively removing it.
NOTE: Make sure the code is ran on the client.
const deleteCookie = (name: string) => {
document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
deleteCookie("test");
NOTE: Make sure the code is ran on the client.
nextjs cookies can only be used on the server side, the question that was asked was 'how can I delete a cookie on the client side in Next.JS app router'
thank you for deleting that