Clearing Cookie in Next.js
Like any other header, a cookie is also a header that web apps use to store essential information. If you want to clear a cookie from server-side in Next.js (which uses node.js under the hood) you can simply use response's setHeader
method like so:
res.setHeader('Set-Cookie', 'some-cookie=someValue; Max-Age=0');
The important part is setting Max-Age=0
, which will make the browser delete that cookie immediately.
PS: This will work for other frameworks and languages too, syntax might be different but Headers work in the same way across all browsers