Place2Play / client /src /utils /storage.ts
3v324v23's picture
feat: initial clean deploy without binary assets
1d87050
raw
history blame contribute delete
689 Bytes
import { v4 as uuidv4 } from 'uuid';
const STORAGE_KEY = 'partygames_user_v1';
export interface UserProfile {
userId: string;
username: string;
avatar: string;
}
export const getUserProfile = (): UserProfile | null => {
if (typeof window === 'undefined') return null;
const stored = localStorage.getItem(STORAGE_KEY);
return stored ? JSON.parse(stored) : null;
};
export const saveUserProfile = (username: string, avatar: string): UserProfile => {
const existing = getUserProfile();
const profile: UserProfile = {
userId: existing?.userId || uuidv4(),
username,
avatar
};
localStorage.setItem(STORAGE_KEY, JSON.stringify(profile));
return profile;
};