how can I delete a cookie on the client side in Next.JS app router
Unanswered
Seppala Siberian Sleddog posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
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
![Avatar](https://cdn.discordapp.com/avatars/603291340528287791/642e035d0c8359e8964c7d6c36b2f7fa.webp?size=256)
Pearls
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.
![Avatar](https://cdn.discordapp.com/avatars/603291340528287791/642e035d0c8359e8964c7d6c36b2f7fa.webp?size=256)
Pearls
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'
![Avatar](https://cdn.discordapp.com/avatars/603291340528287791/642e035d0c8359e8964c7d6c36b2f7fa.webp?size=256)
Pearls
thank you for deleting that