17 lines
542 B
TypeScript
17 lines
542 B
TypeScript
export function setCookie (name: string, value: string): void {
|
|
const maxAge = 60 * 60 * 24 * 90
|
|
const cookie = `${encodeURIComponent(name)}=${encodeURIComponent(
|
|
value
|
|
)}; Path=/; Max-Age=${maxAge}; Secure; SameSite=Strict`
|
|
document.cookie = cookie
|
|
}
|
|
|
|
export function getCookie (name: string, defaultValue: string): string {
|
|
const cookies = document.cookie.split('; ')
|
|
for (const c of cookies) {
|
|
const [k, v] = c.split('=')
|
|
if (decodeURIComponent(k) === name) return decodeURIComponent(v)
|
|
}
|
|
return defaultValue
|
|
}
|