2025-01-30 16:17:36 +00:00
|
|
|
// Client-side storage utilities
|
|
|
|
const isClient = typeof window !== 'undefined' && typeof localStorage !== 'undefined';
|
|
|
|
|
|
|
|
export function getLocalStorage(key: string): any | null {
|
|
|
|
if (!isClient) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2025-01-20 08:53:15 +00:00
|
|
|
try {
|
|
|
|
const item = localStorage.getItem(key);
|
|
|
|
return item ? JSON.parse(item) : null;
|
|
|
|
} catch (error) {
|
|
|
|
console.error(`Error reading from localStorage key "${key}":`, error);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-30 16:17:36 +00:00
|
|
|
export function setLocalStorage(key: string, value: any): void {
|
|
|
|
if (!isClient) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-01-20 08:53:15 +00:00
|
|
|
try {
|
|
|
|
localStorage.setItem(key, JSON.stringify(value));
|
|
|
|
} catch (error) {
|
|
|
|
console.error(`Error writing to localStorage key "${key}":`, error);
|
|
|
|
}
|
|
|
|
}
|