Hi,
Sometimes it's a bit cumbersome to have to define cookie domain by hand for each app. Most scripts set their cookie on currentdomain.com or .currentdomain.com.
One idea would be:
- if a domain is set in the cookies app config, do the same thing as before, ie try to delete the cookie with the given name and domain and that's it
- if no domain is set in the cookies app config, to try to delete multiple cookies for the same cookie name, one for each domain.
The deleteCookie function could look like that:
export function deleteCookie(name, path, domain) {
let cookieString = `${name}=; Max-Age=-99999999;${path !== undefined
? ` path=${path};`
: ` path=/;`
}`
if (domain !== undefined) {
document.cookie = `${cookieString} domain=${domain};`
return;
}
// if domain is not defined, try to delete cookie on multiple default domains
document.cookie = cookieString
document.cookie = `${cookieString} domain=.${location.hostname};`
// handle subdomains
document.cookie = `${cookieString} domain=.${location.hostname.split('.').slice(-2).join('.')};`
}
Would you see any disadvantage of doing this? I know it's something tarteaucitron, a tool similar to Klaro, does and it works pretty well (see here).
Hi,
Sometimes it's a bit cumbersome to have to define cookie domain by hand for each app. Most scripts set their cookie on
currentdomain.comor.currentdomain.com.One idea would be:
The
deleteCookiefunction could look like that:Would you see any disadvantage of doing this? I know it's something tarteaucitron, a tool similar to Klaro, does and it works pretty well (see here).