import React, { useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../context/AuthContext'; const Home = () => { const navigate = useNavigate(); const { user, loginAnonymous, isAuthenticated } = useAuth(); useEffect(() => { const initAuth = async () => { if (!isAuthenticated) { try { await loginAnonymous('Гость'); } catch (error) { console.error('Auto login failed:', error); } } }; initAuth(); }, [isAuthenticated, loginAnonymous]); const handleCreateRoom = () => { navigate('/create-room'); }; const handleJoinRoom = () => { navigate('/join-room'); }; const handleLocalGame = () => { navigate('/local-game'); }; return (
{user ? `Привет, ${user.name}!` : 'Добро пожаловать!'}
Игр сыграно: {user.gamesPlayed || 0}
Побед: {user.gamesWon || 0}
Очков: {user.totalPoints || 0}