From fa7339b0f1eddec331d9d1d97b8d3f9df829682c Mon Sep 17 00:00:00 2001 From: maxime Date: Sun, 24 Mar 2024 20:00:02 +0100 Subject: [PATCH] add a keep alive session loop --- src/App.tsx | 12 ++++++++++++ src/pages/LoginPage.tsx | 1 - src/pages/Settings.tsx | 5 ----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index b947ccc..02f6989 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -17,6 +17,8 @@ const NewTacticPage = lazy(() => import("./pages/NewTacticPage.tsx")) const Editor = lazy(() => import("./pages/Editor.tsx")) const Settings = lazy(() => import("./pages/Settings.tsx")) +const TOKEN_REFRESH_INTERVAL_MS = 60 * 1000 + export default function App() { function suspense(node: ReactNode) { return ( @@ -37,6 +39,16 @@ export default function App() { storeAuthentication(auth) }, [fetcher]) + + useEffect(() => { + const interval = setInterval(() => { + fetcher.fetchAPIGet("auth/keep-alive") + console.log("KEPT ALIVE !") + }, TOKEN_REFRESH_INTERVAL_MS) + + return () => clearInterval(interval) + }, [fetcher]) + return (
diff --git a/src/pages/LoginPage.tsx b/src/pages/LoginPage.tsx index 421761f..458e5dc 100644 --- a/src/pages/LoginPage.tsx +++ b/src/pages/LoginPage.tsx @@ -33,7 +33,6 @@ export default function LoginApp({onSuccess}: LoginAppProps) { const { token, expirationDate } = await response.json() const auth = { token, expirationDate: new Date(expirationDate) } onSuccess(auth) - console.log(location) navigate(location.state?.from || "/") return } diff --git a/src/pages/Settings.tsx b/src/pages/Settings.tsx index 6093c86..4bf0c37 100644 --- a/src/pages/Settings.tsx +++ b/src/pages/Settings.tsx @@ -46,8 +46,6 @@ function ProfilSettings() { const [modalShow, setModalShow] = useState(false) const width = 150 - console.log(user) - const profilePicture = user!.profilePicture return ( @@ -101,7 +99,6 @@ function ProfilSettings() { const password = passwordRef.current?.value const confirmPassword = confirmPasswordRef.current?.value - console.log(password, confirmPassword, name, email) if (password !== confirmPassword) { setErrorMessages(["Les mots de passe ne correspondent pas !"]) return @@ -207,8 +204,6 @@ async function imageExists(imageLink: string) { try { const response = await fetch(imageLink) - console.log(response) - if (response.ok) { const contentType = response.headers.get("content-type") return contentType?.startsWith("image/") ?? false