Skip to content
Merged
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
43 changes: 25 additions & 18 deletions frontend/src/auth/RequireAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
() => [
Expand All @@ -24,31 +29,33 @@ const RequireAuth = () => {
[handleLoginRedirect]
);

if (!isLoggedIn) {
return <Navigate to="/login" />;
}

if (location.pathname === "/") {
return <Navigate to="/project/list" />;
}

return (
<>
<Outlet />
// Show session expired modal instead of silently redirecting
if (!isLoggedIn && showSessionExpiredModal) {
return (
<Modal
title="Session Expired"
open={showSessionExpiredModal}
open
centered
footer={modalFooter}
closable={false}
maskClosable={false}
>
<Typography>
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.
</Typography>
</Modal>
</>
);
);
}

if (!isLoggedIn) {
return <Navigate to="/login" />;
}

if (location.pathname === "/") {
return <Navigate to="/project/list" />;
}

return <Outlet />;
};

export { RequireAuth };
1 change: 1 addition & 0 deletions frontend/src/service/axios-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/service/notification-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down
Loading