Add a way to login to your account on the website
This commit is contained in:
16
src/util/cookie.ts
Normal file
16
src/util/cookie.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user