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

23 lines
649 B
TypeScript

import { readIdentity, writeIdentity } from '../utils/identity';
export function useIdentity() {
const name = useState<string | null>('identity-name', () => null);
const loaded = useState('identity-loaded', () => false);
if (import.meta.client && !loaded.value) {
const identity = readIdentity(window.localStorage);
name.value = identity?.name ?? null;
loaded.value = true;
}
function setName(newName: string) {
const trimmed = newName.trim();
if (!trimmed) return;
name.value = trimmed;
if (import.meta.client)
writeIdentity(window.localStorage, { name: trimmed });
}
return { name, setName };
}