mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 06:28:11 +00:00
Merge pull request #3490 from Infisical/ENG-2546
feat(auth): Persist pre-login-redirect path and redirect after login
This commit is contained in:
@@ -6,6 +6,8 @@ import { ROUTE_PATHS } from "@app/const/routes";
|
|||||||
import { userKeys } from "@app/hooks/api";
|
import { userKeys } from "@app/hooks/api";
|
||||||
import { authKeys, fetchAuthToken } from "@app/hooks/api/auth/queries";
|
import { authKeys, fetchAuthToken } from "@app/hooks/api/auth/queries";
|
||||||
import { clearSession, fetchUserDetails, logoutUser } from "@app/hooks/api/users/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")({
|
export const Route = createFileRoute("/_authenticate")({
|
||||||
beforeLoad: async ({ context, location }) => {
|
beforeLoad: async ({ context, location }) => {
|
||||||
@@ -24,6 +26,16 @@ export const Route = createFileRoute("/_authenticate")({
|
|||||||
title: "Access Restricted",
|
title: "Access Restricted",
|
||||||
text: " You need to log in to access this page. Please log in to continue."
|
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({
|
throw redirect({
|
||||||
to: "/login"
|
to: "/login"
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user