fix(client): migrate digital storage keys
This commit is contained in:
@@ -122,11 +122,12 @@ interface RoleContextValue {
|
||||
|
||||
const RoleContext = createContext<RoleContextValue | null>(null);
|
||||
|
||||
const STORAGE_KEY = 'sgrobot-console-role';
|
||||
const STORAGE_KEY = 'qimingclaw:digital-console-role';
|
||||
const LEGACY_STORAGE_KEY = 'sgrobot-console-role';
|
||||
|
||||
function getStoredRole(): ConsoleRole {
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
const stored = localStorage.getItem(STORAGE_KEY) ?? localStorage.getItem(LEGACY_STORAGE_KEY);
|
||||
if (stored && stored in ROLE_PROFILES) return stored as ConsoleRole;
|
||||
} catch { /* localStorage blocked */ }
|
||||
return 'sales';
|
||||
@@ -137,7 +138,10 @@ export function RoleProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
const setRole = useCallback((newRole: ConsoleRole) => {
|
||||
setRoleState(newRole);
|
||||
try { localStorage.setItem(STORAGE_KEY, newRole); } catch { /* noop */ }
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, newRole);
|
||||
localStorage.removeItem(LEGACY_STORAGE_KEY);
|
||||
} catch { /* noop */ }
|
||||
}, []);
|
||||
|
||||
const profile = ROLE_PROFILES[role];
|
||||
|
||||
Reference in New Issue
Block a user