feat: complete login and user management flow

This commit is contained in:
hectorzhao
2026-07-02 16:28:48 +08:00
parent 9c639d54b9
commit e26d8324c3
22 changed files with 1320 additions and 300 deletions
+42
View File
@@ -0,0 +1,42 @@
export type Portal = 'admin' | 'client';
export type SessionUser = {
id: string;
tenantId?: string | null;
tenantName?: string | null;
username: string;
email?: string | null;
phone?: string | null;
displayName: string;
roles: string[];
};
export type LoginSession = {
accessToken: string;
tokenType: string;
portal: Portal;
user: SessionUser;
};
const sessionKey = 'cmpp-auth-session';
export function readSession(): LoginSession | null {
try {
const raw = window.localStorage.getItem(sessionKey);
return raw ? JSON.parse(raw) as LoginSession : null;
} catch {
return null;
}
}
export function writeSession(session: LoginSession) {
window.localStorage.setItem(sessionKey, JSON.stringify(session));
}
export function clearSession() {
window.localStorage.removeItem(sessionKey);
}
export function getSessionTenantId() {
return readSession()?.user.tenantId ?? undefined;
}