Skip to content

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

fix(frontend): show error states on blank OAuth callback and login error pages (#9026)

Andrew Huang95b7e79261f0
diff --git a/frontend/src/pages/auth/ProviderErrorPage/ProviderErrorPage.tsx b/frontend/src/pages/auth/ProviderErrorPage/ProviderErrorPage.tsx
index 049a9770f6..c933653450 100644
--- a/frontend/src/pages/auth/ProviderErrorPage/ProviderErrorPage.tsx
+++ b/frontend/src/pages/auth/ProviderErrorPage/ProviderErrorPage.tsx
@@ -1,17 +1,44 @@
-import { useEffect } from "react";
+import { Link } from "@tanstack/react-router";
+import { ArrowLeftIcon, LogInIcon, UserXIcon } from "lucide-react";
-import { PageTitle } from "@app/components/PageTitle";
+import { Button } from "@app/components/v3";
+import { ErrorPageFrame, useErrorPageTimestamp } from "@app/pages/public/ErrorPage/components";
export const LoginProviderErrorPage = () => {
- useEffect(() => {
- window.localStorage.setItem("PROVIDER_AUTH_ERROR", "err");
- window.close();
- }, []);
+ const occurredAt = useErrorPageTimestamp();
return (
- <>
- <PageTitle title="Login Failed" />
- <div />
- </>
+ <ErrorPageFrame
+ pageTitle="Login Failed"
+ badgeIcon={<UserXIcon />}
+ badgeText="Login Failed"
+ heading="We couldn't sign you in."
+ description="Your sign-in provider didn't complete the login. Go back to the login page and try again."
+ actions={
+ <Button variant="project" asChild>
+ <Link to="/login">
+ <ArrowLeftIcon />
+ Back to Login
+ </Link>
+ </Button>
+ }
+ statusRows={[
+ {
+ icon: <LogInIcon />,
+ label: "Sign-in provider",
+ state: "Not completed",
+ tone: "warning"
+ }
+ ]}
+ monoRows={[
+ ["route", window.location.pathname],
+ ["time", occurredAt]
+ ]}
+ report={[
+ `route: ${window.location.pathname}`,
+ "error: Sign-in provider did not complete the login",
+ `time: ${occurredAt}`
+ ].join("\n")}
+ />
);
};
diff --git a/frontend/src/pages/secret-manager/integrations/AzureAppConfigurationOauthCallbackPage/AzureAppConfigurationOauthCallbackPage.tsx b/frontend/src/pages/secret-manager/integrations/AzureAppConfigurationOauthCallbackPage/AzureAppConfigurationOauthCallbackPage.tsx
index b2211565be..9a2ed02f0e 100644
--- a/frontend/src/pages/secret-manager/integrations/AzureAppConfigurationOauthCallbackPage/AzureAppConfigurationOauthCallbackPage.tsx
+++ b/frontend/src/pages/secret-manager/integrations/AzureAppConfigurationOauthCallbackPage/AzureAppConfigurationOauthCallbackPage.tsx
@@ -1,14 +1,20 @@
-import { useEffect } from "react";
+import { useEffect, useRef, useState } from "react";
import { useNavigate, useSearch } from "@tanstack/react-router";
-import { PageTitle } from "@app/components/PageTitle";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization, useProject } from "@app/context";
import { useAuthorizeIntegration } from "@app/hooks/api";
+import {
+ IntegrationOauthCallbackStatus,
+ INVALID_OAUTH_STATE_MESSAGE
+} from "../components/IntegrationOauthCallbackStatus";
+
export const AzureAppConfigurationOauthCallbackPage = () => {
const navigate = useNavigate();
const { mutateAsync } = useAuthorizeIntegration();
+ const [error, setError] = useState<string | null>(null);
+ const hasStarted = useRef(false);
const { currentOrg } = useOrganization();
const { code, state } = useSearch({
from: ROUTE_PATHS.SecretManager.Integratons.AzureAppConfigurationsOauthCallbackPage.id
@@ -16,10 +22,17 @@ export const AzureAppConfigurationOauthCallbackPage = () => {
const { currentProject } = useProject();
useEffect(() => {
+ // Runs once: a second run under StrictMode would find the CSRF token already consumed.
+ if (hasStarted.current) return;
+ hasStarted.current = true;
+
(async () => {
try {
// validate state
- if (state !== localStorage.getItem("latestCSRFToken")) return;
+ if (state !== localStorage.getItem("latestCSRFToken")) {
+ setError(INVALID_OAUTH_STATE_MESSAGE);
+ return;
+ }
localStorage.removeItem("latestCSRFToken");
const integrationAuth = await mutateAsync({
@@ -36,18 +49,15 @@ export const AzureAppConfigurationOauthCallbackPage = () => {
},
search: {
integrationAuthId: integrationAuth.id
- }
+ },
+ replace: true
});
} catch (err) {
console.error(err);
+ setError("Infisical couldn't finish authorizing with Azure App Configuration.");
}
})();
}, []);
- return (
- <>
- <PageTitle title="Connecting Azure App Configuration Integration" />
- <div />
- </>
- );
+ return <IntegrationOauthCallbackStatus integrationName="Azure App Configuration" error={error} />;
};
diff --git a/frontend/src/pages/secret-manager/integrations/AzureKeyVaultOauthCallbackPage/AzureKeyVaultOauthCallback.tsx b/frontend/src/pages/secret-manager/integrations/AzureKeyVaultOauthCallbackPage/AzureKeyVaultOauthCallback.tsx
index f697c3ee36..e09d6098dd 100644
--- a/frontend/src/pages/secret-manager/integrations/AzureKeyVaultOauthCallbackPage/AzureKeyVaultOauthCallback.tsx
+++ b/frontend/src/pages/secret-manager/integrations/AzureKeyVaultOauthCallbackPage/AzureKeyVaultOauthCallback.tsx
@@ -1,14 +1,20 @@
-import { useEffect } from "react";
+import { useEffect, useRef, useState } from "react";
import { useNavigate, useSearch } from "@tanstack/react-router";
-import { PageTitle } from "@app/components/PageTitle";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization, useProject } from "@app/context";
import { useAuthorizeIntegration } from "@app/hooks/api";
+import {
+ IntegrationOauthCallbackStatus,
+ INVALID_OAUTH_STATE_MESSAGE
+} from "../components/IntegrationOauthCallbackStatus";
+
export const AzureKeyVaultOauthCallbackPage = () => {
const navigate = useNavigate();
const { mutateAsync } = useAuthorizeIntegration();
+ const [error, setError] = useState<string | null>(null);
+ const hasStarted = useRef(false);
const { currentOrg } = useOrganization();
const { code, state } = useSearch({
from: ROUTE_PATHS.SecretManager.Integratons.AzureKeyVaultOauthCallbackPage.id
@@ -16,10 +22,17 @@ export const AzureKeyVaultOauthCallbackPage = () => {
const { currentProject } = useProject();
useEffect(() => {
+ // Runs once: a second run under StrictMode would find the CSRF token already consumed.
+ if (hasStarted.current) return;
+ hasStarted.current = true;
+
(async () => {
try {
// validate state
- if (state !== localStorage.getItem("latestCSRFToken")) return;
+ if (state !== localStorage.getItem("latestCSRFToken")) {
+ setError(INVALID_OAUTH_STATE_MESSAGE);
+ return;
+ }
localStorage.removeItem("latestCSRFToken");
const integrationAuth = await mutateAsync({
@@ -36,18 +49,15 @@ export const AzureKeyVaultOauthCallbackPage = () => {
},
search: {
integrationAuthId: integrationAuth.id
- }
+ },
+ replace: true
});
} catch (err) {
console.error(err);
+ setError("Infisical couldn't finish authorizing with Azure Key Vault.");
}
})();
}, []);
- return (
- <>
- <PageTitle title="Connecting Azure Key Vault Integration" />
- <div />
- </>
- );
+ return <IntegrationOauthCallbackStatus integrationName="Azure Key Vault" error={error} />;
};
diff --git a/frontend/src/pages/secret-manager/integrations/BitbucketOauthCallbackPage/BitbucketOauthCallbackPage.tsx b/frontend/src/pages/secret-manager/integrations/BitbucketOauthCallbackPage/BitbucketOauthCallbackPage.tsx
index 28eab88a3a..f1c5a07605 100644
--- a/frontend/src/pages/secret-manager/integrations/BitbucketOauthCallbackPage/BitbucketOauthCallbackPage.tsx
+++ b/frontend/src/pages/secret-manager/integrations/BitbucketOauthCallbackPage/BitbucketOauthCallbackPage.tsx
@@ -1,14 +1,20 @@
-import { useEffect } from "react";
+import { useEffect, useRef, useState } from "react";
import { useNavigate, useSearch } from "@tanstack/react-router";
-import { PageTitle } from "@app/components/PageTitle";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization, useProject } from "@app/context";
import { useAuthorizeIntegration } from "@app/hooks/api";
+import {
+ IntegrationOauthCallbackStatus,
+ INVALID_OAUTH_STATE_MESSAGE
+} from "../components/IntegrationOauthCallbackStatus";
+
export const BitbucketOauthCallbackPage = () => {
const navigate = useNavigate();
const { mutateAsync } = useAuthorizeIntegration();
+ const [error, setError] = useState<string | null>(null);
+ const hasStarted = useRef(false);
const { currentOrg } = useOrganization();
const { code, state } = useSearch({
from: ROUTE_PATHS.SecretManager.Integratons.BitbucketOauthCallbackPage.id
@@ -16,10 +22,17 @@ export const BitbucketOauthCallbackPage = () => {
const { currentProject } = useProject();
useEffect(() => {
+ // Runs once: a second run under StrictMode would find the CSRF token already consumed.
+ if (hasStarted.current) return;
+ hasStarted.current = true;
+
(async () => {
try {
// validate state
- if (state !== localStorage.getItem("latestCSRFToken")) return;
+ if (state !== localStorage.getItem("latestCSRFToken")) {
+ setError(INVALID_OAUTH_STATE_MESSAGE);
+ return;
+ }
localStorage.removeItem("latestCSRFToken");
const integrationAuth = await mutateAsync({
@@ -36,18 +49,15 @@ export const BitbucketOauthCallbackPage = () => {
},
search: {
integrationAuthId: integrationAuth.id
- }
+ },
+ replace: true
});
} catch (err) {
console.error(err);
+ setError("Infisical couldn't finish authorizing with Bitbucket.");
}
})();
}, []);
- return (
- <>
- <PageTitle title="Connecting Bitbucket Integration" />
- <div />
- </>
- );
+ return <IntegrationOauthCallbackStatus integrationName="Bitbucket" error={error} />;
};
diff --git a/frontend/src/pages/secret-manager/integrations/GcpSecretManagerOauthCallbackPage/GcpSecretManagerOauthCallbackPage.tsx b/frontend/src/pages/secret-manager/integrations/GcpSecretManagerOauthCallbackPage/GcpSecretManagerOauthCallbackPage.tsx
index 7ed1784fe1..8f593b80fc 100644
--- a/frontend/src/pages/secret-manager/integrations/GcpSecretManagerOauthCallbackPage/GcpSecretManagerOauthCallbackPage.tsx
+++ b/frontend/src/pages/secret-manager/integrations/GcpSecretManagerOauthCallbackPage/GcpSecretManagerOauthCallbackPage.tsx
@@ -1,14 +1,20 @@
-import { useEffect } from "react";
+import { useEffect, useRef, useState } from "react";
import { useNavigate, useSearch } from "@tanstack/react-router";
-import { PageTitle } from "@app/components/PageTitle";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization, useProject } from "@app/context";
import { useAuthorizeIntegration } from "@app/hooks/api";
+import {
+ IntegrationOauthCallbackStatus,
+ INVALID_OAUTH_STATE_MESSAGE
+} from "../components/IntegrationOauthCallbackStatus";
+
export const GcpSecretManagerOauthCallbackPage = () => {
const navigate = useNavigate();
const { mutateAsync } = useAuthorizeIntegration();
+ const [error, setError] = useState<string | null>(null);
+ const hasStarted = useRef(false);
const { currentOrg } = useOrganization();
const { code, state } = useSearch({
from: ROUTE_PATHS.SecretManager.Integratons.GcpSecretManagerOauthCallbackPage.id
@@ -16,11 +22,18 @@ export const GcpSecretManagerOauthCallbackPage = () => {
const { currentProject } = useProject();
useEffect(() => {
+ // Runs once: a second run under StrictMode would find the CSRF token already consumed.
+ if (hasStarted.current) return;
+ hasStarted.current = true;
+
(async () => {
try {
// validate state
- if (state !== localStorage.getItem("latestCSRFToken")) return;
+ if (state !== localStorage.getItem("latestCSRFToken")) {
+ setError(INVALID_OAUTH_STATE_MESSAGE);
+ return;
+ }
localStorage.removeItem("latestCSRFToken");
const integrationAuth = await mutateAsync({
workspaceId: currentProject.id,
@@ -36,18 +49,15 @@ export const GcpSecretManagerOauthCallbackPage = () => {
},
search: {
integrationAuthId: integrationAuth.id
- }
+ },
+ replace: true
});
} catch (err) {
console.error(err);
+ setError("Infisical couldn't finish authorizing with GCP Secret Manager.");
}
})();
}, []);
- return (
- <>
- <PageTitle title="Connecting GCP Secret Manager Integration" />
- <div />
- </>
- );
+ return <IntegrationOauthCallbackStatus integrationName="GCP Secret Manager" error={error} />;
};
diff --git a/frontend/src/pages/secret-manager/integrations/GithubOauthCallbackPage/GithubOauthCallbackPage.tsx b/frontend/src/pages/secret-manager/integrations/GithubOauthCallbackPage/GithubOauthCallbackPage.tsx
index ff2cd18e5e..d223e43010 100644
--- a/frontend/src/pages/secret-manager/integrations/GithubOauthCallbackPage/GithubOauthCallbackPage.tsx
+++ b/frontend/src/pages/secret-manager/integrations/GithubOauthCallbackPage/GithubOauthCallbackPage.tsx
@@ -1,14 +1,20 @@
-import { useEffect } from "react";
+import { useEffect, useRef, useState } from "react";
import { useNavigate, useSearch } from "@tanstack/react-router";
-import { PageTitle } from "@app/components/PageTitle";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization, useProject } from "@app/context";
import { useAuthorizeIntegration } from "@app/hooks/api";
+import {
+ IntegrationOauthCallbackStatus,
+ INVALID_OAUTH_STATE_MESSAGE
+} from "../components/IntegrationOauthCallbackStatus";
+
export const GithubOauthCallbackPage = () => {
const navigate = useNavigate();
const { mutateAsync } = useAuthorizeIntegration();
+ const [error, setError] = useState<string | null>(null);
+ const hasStarted = useRef(false);
const { currentOrg } = useOrganization();
const {
code,
@@ -20,10 +26,15 @@ export const GithubOauthCallbackPage = () => {
const { currentProject } = useProject();
useEffect(() => {
+ // Runs once: a second run under StrictMode would find the CSRF token already consumed.
+ if (hasStarted.current) return;
+ hasStarted.current = true;
+
(async () => {
try {
// validate state
if (state !== localStorage.getItem("latestCSRFToken")) {
+ setError(INVALID_OAUTH_STATE_MESSAGE);
return;
}
@@ -44,18 +55,15 @@ export const GithubOauthCallbackPage = () => {
},
search: {
integrationAuthId: integrationAuth.id
- }
+ },
+ replace: true
});
} catch (err) {
console.error(err);
+ setError("Infisical couldn't finish authorizing with GitHub.");
}
})();
}, []);
- return (
- <>
- <PageTitle title="Connecting GitHub Integration" />
- <div />
- </>
- );
+ return <IntegrationOauthCallbackStatus integrationName="GitHub" error={error} />;
};
diff --git a/frontend/src/pages/secret-manager/integrations/NetlifyOauthCallbackPage/NetlifyOauthCallbackPage.tsx b/frontend/src/pages/secret-manager/integrations/NetlifyOauthCallbackPage/NetlifyOauthCallbackPage.tsx
index e1a89bb50d..cc32403daa 100644
--- a/frontend/src/pages/secret-manager/integrations/NetlifyOauthCallbackPage/NetlifyOauthCallbackPage.tsx
+++ b/frontend/src/pages/secret-manager/integrations/NetlifyOauthCallbackPage/NetlifyOauthCallbackPage.tsx
@@ -1,14 +1,20 @@
-import { useEffect } from "react";
+import { useEffect, useRef, useState } from "react";
import { useNavigate, useSearch } from "@tanstack/react-router";
-import { PageTitle } from "@app/components/PageTitle";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization, useProject } from "@app/context";
import { useAuthorizeIntegration } from "@app/hooks/api";
+import {
+ IntegrationOauthCallbackStatus,
+ INVALID_OAUTH_STATE_MESSAGE
+} from "../components/IntegrationOauthCallbackStatus";
+
export const NetlifyOauthCallbackPage = () => {
const navigate = useNavigate();
const { mutateAsync } = useAuthorizeIntegration();
+ const [error, setError] = useState<string | null>(null);
+ const hasStarted = useRef(false);
const { currentOrg } = useOrganization();
const { code, state } = useSearch({
from: ROUTE_PATHS.SecretManager.Integratons.NetlifyOuathCallbackPage.id
@@ -16,10 +22,17 @@ export const NetlifyOauthCallbackPage = () => {
const { currentProject } = useProject();
useEffect(() => {
+ // Runs once: a second run under StrictMode would find the CSRF token already consumed.
+ if (hasStarted.current) return;
+ hasStarted.current = true;
+
(async () => {
try {
// validate state
- if (state !== localStorage.getItem("latestCSRFToken")) return;
+ if (state !== localStorage.getItem("latestCSRFToken")) {
+ setError(INVALID_OAUTH_STATE_MESSAGE);
+ return;
+ }
localStorage.removeItem("latestCSRFToken");
const integrationAuth = await mutateAsync({
@@ -36,18 +49,15 @@ export const NetlifyOauthCallbackPage = () => {
},
search: {
integrationAuthId: integrationAuth.id
- }
+ },
+ replace: true
});
} catch (err) {
console.error(err);
+ setError("Infisical couldn't finish authorizing with Netlify.");
}
})();
}, []);
- return (
- <>
- <PageTitle title="Connecting Netlify Integration" />
- <div />
- </>
- );
+ return <IntegrationOauthCallbackStatus integrationName="Netlify" error={error} />;
};
diff --git a/frontend/src/pages/secret-manager/integrations/VercelOauthCallbackPage/VercelOauthCallbackPage.tsx b/frontend/src/pages/secret-manager/integrations/VercelOauthCallbackPage/VercelOauthCallbackPage.tsx
index e5cea75277..415c740099 100644
--- a/frontend/src/pages/secret-manager/integrations/VercelOauthCallbackPage/VercelOauthCallbackPage.tsx
+++ b/frontend/src/pages/secret-manager/integrations/VercelOauthCallbackPage/VercelOauthCallbackPage.tsx
@@ -1,14 +1,20 @@
-import { useEffect } from "react";
+import { useEffect, useRef, useState } from "react";
import { useNavigate, useSearch } from "@tanstack/react-router";
-import { PageTitle } from "@app/components/PageTitle";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization, useProject } from "@app/context";
import { useAuthorizeIntegration } from "@app/hooks/api";
+import {
+ IntegrationOauthCallbackStatus,
+ INVALID_OAUTH_STATE_MESSAGE
+} from "../components/IntegrationOauthCallbackStatus";
+
export const VercelOauthCallbackPage = () => {
const navigate = useNavigate();
const { mutateAsync } = useAuthorizeIntegration();
+ const [error, setError] = useState<string | null>(null);
+ const hasStarted = useRef(false);
const { currentOrg } = useOrganization();
const { code, state } = useSearch({
from: ROUTE_PATHS.SecretManager.Integratons.VercelOauthCallbackPage.id
@@ -16,10 +22,17 @@ export const VercelOauthCallbackPage = () => {
const { currentProject } = useProject();
useEffect(() => {
+ // Runs once: a second run under StrictMode would find the CSRF token already consumed.
+ if (hasStarted.current) return;
+ hasStarted.current = true;
+
(async () => {
try {
// validate state
- if (state !== localStorage.getItem("latestCSRFToken")) return;
+ if (state !== localStorage.getItem("latestCSRFToken")) {
+ setError(INVALID_OAUTH_STATE_MESSAGE);
+ return;
+ }
localStorage.removeItem("latestCSRFToken");
const integrationAuth = await mutateAsync({
@@ -36,18 +49,15 @@ export const VercelOauthCallbackPage = () => {
},
search: {
integrationAuthId: integrationAuth.id
- }
+ },
+ replace: true
});
} catch (err) {
console.error(err);
+ setError("Infisical couldn't finish authorizing with Vercel.");
}
})();
}, []);
- return (
- <>
- <PageTitle title="Connecting Vercel Integration" />
- <div />
- </>
- );
+ return <IntegrationOauthCallbackStatus integrationName="Vercel" error={error} />;
};
diff --git a/frontend/src/pages/secret-manager/integrations/components/IntegrationOauthCallbackStatus.tsx b/frontend/src/pages/secret-manager/integrations/components/IntegrationOauthCallbackStatus.tsx
new file mode 100644
index 0000000000..74fa34e60d
--- /dev/null
+++ b/frontend/src/pages/secret-manager/integrations/components/IntegrationOauthCallbackStatus.tsx
@@ -0,0 +1,81 @@
+import { Link } from "@tanstack/react-router";
+import { ArrowLeftIcon, PlugZapIcon, UnplugIcon } from "lucide-react";
+
+import { PageTitle } from "@app/components/PageTitle";
+import { Button } from "@app/components/v3";
+import { PageLoader } from "@app/components/v3/platform/PageLoader";
+import { ROUTE_PATHS } from "@app/const/routes";
+import { useOrganization, useProject } from "@app/context";
+import { ErrorPageFrame, useErrorPageTimestamp } from "@app/pages/public/ErrorPage/components";
+import { IntegrationsListPageTabs } from "@app/types/integrations";
+
+export const INVALID_OAUTH_STATE_MESSAGE =
+ "This authorization link is no longer valid. It may have expired, or it was started in another browser or tab.";
+
+const ConnectionFailed = ({
+ integrationName,
+ error
+}: {
+ integrationName: string;
+ error: string;
+}) => {
+ const { currentOrg } = useOrganization();
+ const { currentProject } = useProject();
+ const occurredAt = useErrorPageTimestamp();
+
+ return (
+ <ErrorPageFrame
+ pageTitle={`${integrationName} Connection Failed`}
+ badgeIcon={<UnplugIcon />}
+ badgeText="Connection Failed"
+ heading={`We couldn't connect ${integrationName}.`}
+ description={`${error} Start the connection again from the Integrations page.`}
+ actions={
+ <Button variant="project" asChild>
+ <Link
+ to={ROUTE_PATHS.SecretManager.IntegrationsListPage.path}
+ params={{ orgId: currentOrg.id, projectId: currentProject.id }}
+ search={{ selectedTab: IntegrationsListPageTabs.NativeIntegrations }}
+ >
+ <ArrowLeftIcon />
+ Back to Integrations
+ </Link>
+ </Button>
+ }
+ statusRows={[
+ {
+ icon: <PlugZapIcon />,
+ label: integrationName,
+ state: "Not connected",
+ tone: "warning"
+ }
+ ]}
+ monoRows={[
+ ["route", window.location.pathname],
+ ["time", occurredAt]
+ ]}
+ report={[
+ `route: ${window.location.pathname}`,
+ `integration: ${integrationName}`,
+ `error: ${error}`,
+ `time: ${occurredAt}`
+ ].join("\n")}
+ />
+ );
+};
+
+type Props = {
+ integrationName: string;
+ error: string | null;
+};
+
+export const IntegrationOauthCallbackStatus = ({ integrationName, error }: Props) => {
+ if (error) return <ConnectionFailed integrationName={integrationName} error={error} />;
+
+ return (
+ <>
+ <PageTitle title={`Connecting ${integrationName} Integration`} />
+ <PageLoader text={`Connecting ${integrationName}...`} />
+ </>
+ );
+};