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 UserContext from '../helpers/UserContext';
10 const [user, setUser] = useState(null);
12 const checkAuth = async () => {
14 const response = await axios.get('/api/user');
15 setUser(response.data);
21 const doLogout = async () => {
22 await axios.post('/logout');
29 .get('/sanctum/csrf-cookie')
32 timer = setInterval(checkAuth, 15 * 60 * 1000);
35 if (timer) clearInterval(timer);
40 window.Echo.channel('App.Control')
41 .listen('PleaseRefresh', () => {
45 window.Echo.leave('App.Control');
49 return <BrowserRouter>
50 <UserContext.Provider value={user}>
51 <Header doLogout={doLogout} />
53 <Route path="tournaments/:id" element={<Tournament />} />
54 <Route path="*" element={<Navigate to="/tournaments/1" />} />
56 </UserContext.Provider>