From 04b20ed11dc4a745edb69a149c81fb03d5900265 Mon Sep 17 00:00:00 2001 From: x Date: Fri, 25 Apr 2025 12:09:18 -0400 Subject: [PATCH] feat(auth): Persist pre-login-redirect path and redirect after login --- frontend/src/pages/middlewares/authenticate.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frontend/src/pages/middlewares/authenticate.tsx b/frontend/src/pages/middlewares/authenticate.tsx index 615d03b60..2f5789096 100644 --- a/frontend/src/pages/middlewares/authenticate.tsx +++ b/frontend/src/pages/middlewares/authenticate.tsx @@ -6,6 +6,8 @@ import { ROUTE_PATHS } from "@app/const/routes"; import { userKeys } from "@app/hooks/api"; import { authKeys, fetchAuthToken } from "@app/hooks/api/auth/queries"; import { clearSession, fetchUserDetails, logoutUser } from "@app/hooks/api/users/queries"; +import { SessionStorageKeys } from "@app/const"; +import { addSeconds, formatISO } from "date-fns"; export const Route = createFileRoute("/_authenticate")({ beforeLoad: async ({ context, location }) => { @@ -24,6 +26,16 @@ export const Route = createFileRoute("/_authenticate")({ title: "Access Restricted", text: " You need to log in to access this page. Please log in to continue." }); + + // persist current URL in session storage so that we can come back to this after successful login + sessionStorage.setItem( + SessionStorageKeys.ORG_LOGIN_SUCCESS_REDIRECT_URL, + JSON.stringify({ + expiry: formatISO(addSeconds(new Date(), 60)), + data: window.location.href + }) + ); + throw redirect({ to: "/login" });