Files
splitt-the-bill/app/utils/identity.ts
T
anbraten cbe1b42f6e
tinyedge/deploy Deployed by TinyEdge
🐛 add env to useDb and apply prettier
2026-08-07 13:28:26 +02:00

26 lines
615 B
TypeScript

const STORAGE_KEY = 'stb:identity';
export interface Identity {
name: string;
}
type StorageLike = Pick<Storage, 'getItem' | 'setItem'>;
export function readIdentity(storage: StorageLike): Identity | null {
const raw = storage.getItem(STORAGE_KEY);
if (!raw) return null;
try {
const parsed = JSON.parse(raw);
if (typeof parsed?.name !== 'string' || !parsed.name.trim()) return null;
return { name: parsed.name };
} catch {
return null;
}
}
export function writeIdentity(storage: StorageLike, identity: Identity): void {
storage.setItem(STORAGE_KEY, JSON.stringify(identity));
}