Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

misc: addressed feedback

Sheen Capadngan5487c2669595
diff --git a/frontend/src/helpers/sessionStorage.ts b/frontend/src/helpers/sessionStorage.ts
new file mode 100644
index 0000000000..187e58e637
--- /dev/null
+++ b/frontend/src/helpers/sessionStorage.ts
@@ -0,0 +1,27 @@
+import { SessionStorageKeys } from "@app/const";
+
+/**
+ * Retrieves and consumes the stored login redirect URL (e.g., from deep links like /pam/access).
+ * Returns the URL if valid and not expired, otherwise undefined.
+ */
+export const consumeLoginRedirectUrl = (): string | undefined => {
+ const loginRedirectInfo = sessionStorage.getItem(
+ SessionStorageKeys.ORG_LOGIN_SUCCESS_REDIRECT_URL
+ );
+ if (!loginRedirectInfo) return undefined;
+
+ sessionStorage.removeItem(SessionStorageKeys.ORG_LOGIN_SUCCESS_REDIRECT_URL);
+
+ try {
+ const { expiry, data: redirectUrl } = JSON.parse(loginRedirectInfo) as {
+ expiry: string;
+ data: string;
+ };
+ if (new Date() < new Date(expiry) && redirectUrl) {
+ return redirectUrl;
+ }
+ } catch {
+ // Invalid JSON - ignore
+ }
+ return undefined;
+};
diff --git a/frontend/src/hooks/api/auth/queries.tsx b/frontend/src/hooks/api/auth/queries.tsx
index 3da0445766..3895f07d5f 100644
--- a/frontend/src/hooks/api/auth/queries.tsx
+++ b/frontend/src/hooks/api/auth/queries.tsx
@@ -2,7 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import SecurityClient from "@app/components/utilities/SecurityClient";
import { apiRequest } from "@app/config/request";
-import { SessionStorageKeys } from "@app/const";
+import { consumeLoginRedirectUrl } from "@app/helpers/sessionStorage";
import { adminQueryKeys } from "../admin";
import { organizationKeys } from "../organization/queries";
@@ -69,31 +69,7 @@ export const selectOrganization = async (data: SelectOrganizationParams) => {
isMfaEnabled: boolean;
mfaMethod?: MfaMethod;
}>("/api/v3/auth/select-organization", data);
-
- // Check for a stored redirect URL from before login (e.g., deep links like /pam/access)
- // Return the URL so the caller can redirect AFTER setting up auth state
- let loginRedirectUrl: string | undefined;
- if (res.token && !res.isMfaEnabled) {
- const loginRedirectInfo = sessionStorage.getItem(
- SessionStorageKeys.ORG_LOGIN_SUCCESS_REDIRECT_URL
- );
- if (loginRedirectInfo) {
- sessionStorage.removeItem(SessionStorageKeys.ORG_LOGIN_SUCCESS_REDIRECT_URL);
- try {
- const { expiry, data: redirectUrl } = JSON.parse(loginRedirectInfo) as {
- expiry: string;
- data: string;
- };
- if (new Date() < new Date(expiry) && redirectUrl) {
- loginRedirectUrl = redirectUrl;
- }
- } catch {
- // Invalid JSON - ignore
- }
- }
- }
-
- return { ...res, loginRedirectUrl };
+ return res;
};
export const useSelectOrganization = () => {
@@ -112,10 +88,12 @@ export const useSelectOrganization = () => {
await queryClient.refetchQueries({ queryKey: adminQueryKeys.serverConfig() });
}
- // If there's a stored redirect URL from before login, navigate there now
- // (after auth state is set up)
- if (data.loginRedirectUrl) {
- window.location.assign(data.loginRedirectUrl);
+ // Check for a stored redirect URL from before login (e.g., deep links)
+ if (data.token && !data.isMfaEnabled) {
+ const redirectUrl = consumeLoginRedirectUrl();
+ if (redirectUrl) {
+ window.location.assign(redirectUrl);
+ }
}
return data;
diff --git a/frontend/src/pages/auth/SelectOrgPage/route.tsx b/frontend/src/pages/auth/SelectOrgPage/route.tsx
index f41df0e3db..527413016c 100644
--- a/frontend/src/pages/auth/SelectOrgPage/route.tsx
+++ b/frontend/src/pages/auth/SelectOrgPage/route.tsx
@@ -6,6 +6,7 @@ import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import { SessionStorageKeys } from "@app/const";
import { isInfisicalCloud } from "@app/helpers/platform";
+import { consumeLoginRedirectUrl } from "@app/helpers/sessionStorage";
import { adminQueryKeys } from "@app/hooks/api/admin/queries";
import { authKeys, selectOrganization } from "@app/hooks/api/auth/queries";
import { UserAgentType } from "@app/hooks/api/auth/types";
@@ -157,10 +158,10 @@ export const Route = createFileRoute("/_restrict-login-signup/login/select-organ
createNotification({ text: "Successfully logged in", type: "success" });
- // If there's a stored redirect URL from before login (e.g., deep links like /pam/access),
- // navigate there instead of the default projects page
- if (result.loginRedirectUrl) {
- window.location.assign(result.loginRedirectUrl);
+ // Check for a stored redirect URL from before login (e.g., deep links like /pam/access)
+ const loginRedirectUrl = consumeLoginRedirectUrl();
+ if (loginRedirectUrl) {
+ window.location.assign(loginRedirectUrl);
return { autoSelectErrorMessage: undefined };
}