Spaces:
Sleeping
Sleeping
| 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; | |
| }; | |