forked from tsai/budibase
5 changed files with 65 additions and 15 deletions
@ -1,16 +1,26 @@ |
|||||
export const Cookies = { |
export const Cookies = { |
||||
Auth: "budibase:auth", |
Auth: "budibase:auth", |
||||
CurrentApp: "budibase:currentapp", |
CurrentApp: "budibase:currentapp", |
||||
|
ReturnUrl: "budibase:returnurl", |
||||
|
} |
||||
|
|
||||
|
export function setCookie(name, value) { |
||||
|
if (getCookie(name)) { |
||||
|
removeCookie(name) |
||||
|
} |
||||
|
window.document.cookie = `${name}=${value}; Path=/;` |
||||
} |
} |
||||
|
|
||||
export function getCookie(cookieName) { |
export function getCookie(cookieName) { |
||||
return document.cookie.split(";").some(cookie => { |
const value = `; ${document.cookie}` |
||||
return cookie.trim().startsWith(`${cookieName}=`) |
const parts = value.split(`; ${cookieName}=`) |
||||
}) |
if (parts.length === 2) { |
||||
|
return parts[1].split(";").shift() |
||||
|
} |
||||
} |
} |
||||
|
|
||||
export function removeCookie(cookieName) { |
export function removeCookie(cookieName) { |
||||
if (getCookie(cookieName)) { |
if (getCookie(cookieName)) { |
||||
document.cookie = `${cookieName}=; Max-Age=-99999999;` |
document.cookie = `${cookieName}=; Max-Age=-99999999; Path=/;` |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue