blob: d653bce6491967666c9a3732a3c0ca1fc5ee89f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import { useState, useEffect } from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import Home from "../components/Home";
import Blogs from "../components/Blogs";
import Games from "../components/Games";
import UploadGame from "../components/UploadGame";
import Game from "../components/Game";
import Layout from "../components/Layout";
import CloseWindow from "../components/CloseWindow";
export default function Index()
{
const [userData, setUserData] = useState({ name: '' });
useEffect(() => {
const url = `${import.meta.env.VITE_API_TITLE}/api/v1/auth/data`;
fetch(url, {
credentials: "include"
}).then((response) => {
if(response.ok) {
return response.json();
}
throw new Error("Network response was not ok.");
}).then((response) => setUserData(response.user_data));}, []);
// get user data here
// then pass it in as 'props' into the components
return (<>
{/*<h1>{userData.login}</h1>*/}
<Router>
<Routes>
<Route path="/" element = {<Layout userData={userData}/>}>
<Route index element={<Home />} />
<Route path="/blogs" element={<Blogs />} />
<Route path="/games" element={<Games />} />
<Route path="/games/upload" element={<UploadGame />} />
<Route path="/game/:game" element={<Game />} />
<Route path="/closewindow" element={<CloseWindow />} />
</Route>
</Routes>
</Router>
</>);
}
|