- Implement user registration and login with NextAuth v5 (email/password, JWT) - Add authentication modal in UI with login/register tabs - Create user profile screen showing game statistics and history - Integrate Prisma 7 ORM with SQLite database for data persistence - Store game results (mode, path, clicks, time) in database - Auto-save completed games only when user is authenticated - Separate business logic into reusable hooks (useSoloGame, useMultiGame) - Organize UI into composable screen components (HomeScreen, SoloScreen, ProfileScreen, etc) - Add session persistence across F5 refresh for solo and multiplayer - Style auth modal, account button, and profile stats dashboard
35 lines
806 B
TypeScript
35 lines
806 B
TypeScript
// Persistence sessionStorage pour F5 / rechargement de page
|
|
|
|
const KEY = "wikirace_session";
|
|
|
|
export type SessionData = {
|
|
screen: "solo" | "lobby" | "game";
|
|
// Solo
|
|
soloPuzzle?: { start: string; target: string };
|
|
soloHistory?: string[];
|
|
soloClicks?: number;
|
|
// Multi
|
|
multiRoomCode?: string;
|
|
multiPlayerId?: string;
|
|
playerName?: string;
|
|
};
|
|
|
|
export function saveSession(data: SessionData) {
|
|
try {
|
|
sessionStorage.setItem(KEY, JSON.stringify(data));
|
|
} catch { /* ignore quota */ }
|
|
}
|
|
|
|
export function loadSession(): SessionData | null {
|
|
try {
|
|
const raw = sessionStorage.getItem(KEY);
|
|
return raw ? (JSON.parse(raw) as SessionData) : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function clearSession() {
|
|
try { sessionStorage.removeItem(KEY); } catch { /* ignore */ }
|
|
}
|