import { Cookies, getCookie, removeCookie, setCookie} from 'typescript-cookie' import { Session, TokenSession } from './lib/session' export const LIFETO_COOKIE_PREFIX="LIFETO_PANEL_" export const nameCookie = (...s:string[]):string=>{ return LIFETO_COOKIE_PREFIX+s.join("_").toUpperCase() } export class Storage { GetSession():Session { const {user, xsrf, csrf} = { user: getCookie(nameCookie("user"))!, xsrf: getCookie(nameCookie("xsrf"))!, csrf: getCookie(nameCookie("csrf"))! } return new TokenSession(user, xsrf, csrf) } RemoveSession() { removeCookie(nameCookie("user")) removeCookie(nameCookie("xsrf")) removeCookie(nameCookie("csrf")) } AddSession(s:Session) { setCookie(nameCookie("user"),s.user) setCookie(nameCookie("xsrf"),s.xsrf) setCookie(nameCookie("csrf"),s.csrf) } } export const storage = new Storage()