1 import axios from 'axios';
2 import React, { useEffect, useState } from 'react';
3 import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
5 import Header from './common/Header';
6 import Tournament from './pages/Tournament';
7 import User from './pages/User';
8 import UserContext from '../helpers/UserContext';
11 const [user, setUser] = useState(null);
13 const checkAuth = async () => {
15 const response = await axios.get('/api/user');
16 setUser(response.data);
22 const doLogout = async () => {
23 await axios.post('/logout');
30 .get('/sanctum/csrf-cookie')
33 timer = setInterval(checkAuth, 15 * 60 * 1000);
36 if (timer) clearInterval(timer);
41 window.Echo.channel('App.Control')
42 .listen('PleaseRefresh', () => {
46 window.Echo.leave('App.Control');
50 return <BrowserRouter>
51 <UserContext.Provider value={user}>
52 <Header doLogout={doLogout} />
54 <Route path="tournaments/:id" element={<Tournament />} />
55 <Route path="users/:id" element={<User />} />
56 <Route path="*" element={<Navigate to="/tournaments/1" />} />
58 </UserContext.Provider>