diff --git a/frontend/src/auth/RequireAuth.js b/frontend/src/auth/RequireAuth.js index 0802c32..0f18eb1 100644 --- a/frontend/src/auth/RequireAuth.js +++ b/frontend/src/auth/RequireAuth.js @@ -5,15 +5,20 @@ import { Navigate, Outlet, useNavigate, useLocation } from "react-router-dom"; import { useSessionStore } from "../store/session-store"; const RequireAuth = () => { - const { showSessionExpiredModal, sessionDetails } = useSessionStore(); + const { + showSessionExpiredModal, + setShowSessionExpiredModal, + sessionDetails, + } = useSessionStore(); const navigate = useNavigate(); const location = useLocation(); const isLoggedIn = !!sessionDetails?.user?.id; const handleLoginRedirect = useCallback(() => { + setShowSessionExpiredModal(false); navigate("/login"); - }, [navigate]); + }, [navigate, setShowSessionExpiredModal]); const modalFooter = useMemo( () => [ @@ -24,31 +29,33 @@ const RequireAuth = () => { [handleLoginRedirect] ); - if (!isLoggedIn) { - return ; - } - - if (location.pathname === "/") { - return ; - } - - return ( - <> - + // Show session expired modal instead of silently redirecting + if (!isLoggedIn && showSessionExpiredModal) { + return ( - Your session has expired. Please log in again to continue your - transformation with Visitran Ai. + Your session has expired. Please log in again to continue. - - ); + ); + } + + if (!isLoggedIn) { + return ; + } + + if (location.pathname === "/") { + return ; + } + + return ; }; export { RequireAuth }; diff --git a/frontend/src/service/axios-service.js b/frontend/src/service/axios-service.js index ee5215c..fa24271 100644 --- a/frontend/src/service/axios-service.js +++ b/frontend/src/service/axios-service.js @@ -31,6 +31,7 @@ function useAxiosPrivate() { if (error?.response?.status === 401) { localStorage.removeItem("orgid"); localStorage.removeItem("session-storage"); + useSessionStore.getState().setShowSessionExpiredModal(true); setSessionDetails({}); return Promise.resolve({ suppressed: true }); } diff --git a/frontend/src/service/notification-service.js b/frontend/src/service/notification-service.js index 8194965..5fc0689 100644 --- a/frontend/src/service/notification-service.js +++ b/frontend/src/service/notification-service.js @@ -10,6 +10,7 @@ import { notification, Button } from "antd"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import "./notification-border.css"; +import { useSessionStore } from "../store/session-store"; const NotificationContext = createContext(null); @@ -50,8 +51,11 @@ function NotificationProvider({ children }) { let finalDescription = description; if (type === "error") { - // Skip notification for 401 errors - session expiry modal handles this - if (error?.response?.status === 401) { + // Skip all notifications when session expired modal is showing + if ( + error?.response?.status === 401 || + useSessionStore.getState().showSessionExpiredModal + ) { return; }