From 9eb3ab91fb653ca6d4921238e2a497427405f178 Mon Sep 17 00:00:00 2001
From: realtradam <github@tradam.dev>
Date: Fri, 28 Jun 2024 17:25:36 -0400
Subject: add login

---
 react-frontend/src/routes/index.tsx | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

(limited to 'react-frontend/src/routes/index.tsx')

diff --git a/react-frontend/src/routes/index.tsx b/react-frontend/src/routes/index.tsx
index 5fcae2b..e22bcc4 100644
--- a/react-frontend/src/routes/index.tsx
+++ b/react-frontend/src/routes/index.tsx
@@ -1,14 +1,38 @@
+import { useState, useEffect } from "react";
 import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
 import Home from "../pages/Home";
 import Layout from "../components/Layout";
+import CloseWindow from "../pages/CloseWindow";
 
 export default function Index()
 {
+
+	const [userData, setUserData] = useState({ name: '' });
+	useEffect(() => {
+		const update_login_status = () => {
+			//localStorage.removeItem("logged in trigger");
+			const url = `${import.meta.env.VITE_API_TITLE}/api/v1/auth/data`;
+			try { fetch(url, {
+				credentials: "include"
+			}).then((response) => {
+				if(response.ok) {
+					return response.json();
+				}
+				//throw new Error("Network response was not ok.");
+			}).then((response) => response && setUserData(response.user_data)).catch((err) => { console.log(err); });}
+			catch(err) { console.log(err); }
+		};
+		window.addEventListener('storage', update_login_status );
+		update_login_status();
+		return () => { window.removeEventListener('storage', update_login_status); };
+	}, []);
+
 	return (<>
 				<Router>
 					<Routes>
-						<Route path="/" element = {<Layout/>}>
+						<Route path="/" element = {<Layout userData={userData}/>}>
 							<Route index element={<Home />} />
+							<Route path="/closewindow" element={<CloseWindow />} />
 						</Route>
 					</Routes>
 				</Router>
-- 
cgit v1.2.3

