This commit is contained in:
chamikaJ
2025-04-17 18:28:54 +05:30
parent f583291d8a
commit 8825b0410a
2837 changed files with 241385 additions and 127578 deletions

View File

@@ -0,0 +1,33 @@
import { ILocalSession } from '@/types/auth/local-session.types';
export const WORKLENZ_SESSION_ID = import.meta.env.VITE_WORKLENZ_SESSION_ID;
const storage: Storage = localStorage;
export function setSession(user: ILocalSession): void {
storage.setItem(WORKLENZ_SESSION_ID, btoa(unescape(encodeURIComponent(JSON.stringify(user)))));
// storage.setItem(WORKLENZ_SESSION_ID, btoa(JSON.stringify(user)));
}
export function getUserSession(): ILocalSession | null {
try {
return JSON.parse(atob(<string>storage.getItem(WORKLENZ_SESSION_ID)));
} catch (e) {
return null;
}
}
export function hasSession() {
return !!storage.getItem(WORKLENZ_SESSION_ID);
}
export function deleteSession() {
storage.removeItem(WORKLENZ_SESSION_ID);
}
export function getRole() {
const session = getUserSession();
if (!session) return 'Unknown';
if (session.owner) return 'Owner';
if (session.is_admin) return 'Admin';
return 'Member';
}