story-research-zapwall/lib/cookieCleanup.ts
2026-01-07 17:09:07 +01:00

31 lines
910 B
TypeScript

/**
* Cookie cleanup utilities
* Removes all cookies from the domain
*/
/**
* Delete all cookies for the current domain
*/
export function deleteAllCookies(): void {
if (typeof document === 'undefined') {
return
}
const cookies = document.cookie.split(';')
for (let i = 0; i < cookies.length; i += 1) {
const cookie = cookies[i]
if (cookie) {
const eqPos = cookie.indexOf('=')
const name = eqPos > -1 ? cookie.substring(0, eqPos).trim() : cookie.trim()
if (name) {
// Delete cookie by setting it to expire in the past
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/`
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=${window.location.hostname}`
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=.${window.location.hostname}`
}
}
}
}