61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
|
|
import type { SessionUser } from '@/types/roles';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Sprint 0 mock — no backend yet. The session is selected from /login
|
||
|
|
* and persisted in sessionStorage so route navigations preserve role.
|
||
|
|
* Real auth lands later (D-003: local user/password v1, Keycloak OIDC v2).
|
||
|
|
*/
|
||
|
|
|
||
|
|
const STORAGE_KEY = 'mimic.mock.session';
|
||
|
|
|
||
|
|
export const MOCK_SESSIONS: Record<string, SessionUser> = {
|
||
|
|
rt_operator: {
|
||
|
|
id: 'usr_001',
|
||
|
|
displayName: 'M. Dubreuil',
|
||
|
|
role: 'rt_operator',
|
||
|
|
engagementId: 'eng_42',
|
||
|
|
engagementName: 'Démo Client X',
|
||
|
|
},
|
||
|
|
rt_lead: {
|
||
|
|
id: 'usr_002',
|
||
|
|
displayName: 'A. Verlhac',
|
||
|
|
role: 'rt_lead',
|
||
|
|
engagementId: 'eng_42',
|
||
|
|
engagementName: 'Démo Client X',
|
||
|
|
},
|
||
|
|
soc_analyst: {
|
||
|
|
id: 'usr_soc_07',
|
||
|
|
displayName: 'SOC · session #07',
|
||
|
|
role: 'soc_analyst',
|
||
|
|
engagementId: 'eng_42',
|
||
|
|
engagementName: 'Démo Client X',
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
export function readMockSession(): SessionUser | null {
|
||
|
|
try {
|
||
|
|
const raw = sessionStorage.getItem(STORAGE_KEY);
|
||
|
|
if (!raw) return null;
|
||
|
|
const parsed: unknown = JSON.parse(raw);
|
||
|
|
if (
|
||
|
|
typeof parsed === 'object' &&
|
||
|
|
parsed !== null &&
|
||
|
|
'role' in parsed &&
|
||
|
|
typeof (parsed as SessionUser).role === 'string'
|
||
|
|
) {
|
||
|
|
return parsed as SessionUser;
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
} catch {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export function writeMockSession(user: SessionUser): void {
|
||
|
|
sessionStorage.setItem(STORAGE_KEY, JSON.stringify(user));
|
||
|
|
}
|
||
|
|
|
||
|
|
export function clearMockSession(): void {
|
||
|
|
sessionStorage.removeItem(STORAGE_KEY);
|
||
|
|
}
|