Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #58 - Premature session timeouts - Kazakh feedback #13

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useCallback } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ToastContainer } from "react-toastify";
import { Root } from "./routes";
Expand Down Expand Up @@ -35,16 +35,6 @@ function App() {
once: false,
});

useEffect(() => {
window.addEventListener("beforeunload", (e) => {
if (!(performance.getEntriesByType("navigation")[0].type === "reload")) {
// If the page is being refreshed, do nothing
e.preventDefault();
userSvc.logout();
}
});
}, []);

const getDefaultTheme = () => {
const localStorageTheme = localStorage.getItem("default-theme");
return localStorageTheme || "light";
Expand All @@ -56,6 +46,18 @@ function App() {
localStorage.setItem("default-theme", theme);
}, [theme]);

const logoutFunction = useCallback(() => {
userSvc.logout();
}, []);

useEffect(() => {
const existingSession = sessionStorage.getItem("userSession");

if (!existingSession) {
logoutFunction();
}
}, []);

return (
<ThemeContext.Provider value={{ theme, setTheme }}>
<div className={`theme-${theme}`}>
Expand Down
1 change: 1 addition & 0 deletions src/pages/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const Login = () => {
localStorage.setItem("token", token);
localStorage.setItem("token-expires-in", expiresIn);
localStorage.setItem("refresh-token", refreshToken);
sessionStorage.setItem("userSession", true);

queryClient.invalidateQueries({ queryKey: ["provider-data"] });

Expand Down
Loading