2022-07-01 01:27:18 +00:00
|
|
|
import { getCookie, setCookie} from 'typescript-cookie'
|
2022-07-03 10:25:12 +00:00
|
|
|
import { Session, TokenSession } from './lib/session'
|
2022-07-01 01:27:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const LIFETO_COOKIE_PREFIX="LIFETO_PANEL_"
|
|
|
|
|
|
|
|
export const nameCookie = (...s:string[]):string=>{
|
|
|
|
return LIFETO_COOKIE_PREFIX+s.join("_").toUpperCase()
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Storage {
|
2022-07-03 10:25:12 +00:00
|
|
|
GetSession():Session {
|
|
|
|
const {user, xsrf, csrf} = {
|
|
|
|
user: getCookie(nameCookie("user"))!,
|
|
|
|
xsrf: getCookie(nameCookie("xsrf"))!,
|
|
|
|
csrf: getCookie(nameCookie("csrf"))!
|
2022-07-01 01:27:18 +00:00
|
|
|
}
|
2022-07-03 10:25:12 +00:00
|
|
|
return new TokenSession(user, xsrf, csrf)
|
2022-07-01 01:27:18 +00:00
|
|
|
}
|
|
|
|
|
2022-07-03 10:25:12 +00:00
|
|
|
RemoveSession() {
|
|
|
|
setCookie(nameCookie("user"),"")
|
|
|
|
setCookie(nameCookie("xsrf"),"")
|
|
|
|
setCookie(nameCookie("csrf"),"")
|
2022-07-01 01:27:18 +00:00
|
|
|
}
|
|
|
|
AddSession(s:Session) {
|
2022-07-03 10:25:12 +00:00
|
|
|
setCookie(nameCookie("user"),s.user)
|
|
|
|
setCookie(nameCookie("xsrf"),s.xsrf)
|
|
|
|
setCookie(nameCookie("csrf"),s.csrf)
|
2022-07-01 01:27:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const storage = new Storage()
|