Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Add a forgot-password link to the desktop Cloud sign-in (#8870)

ConnorYohee8c2b3a9fc5
diff --git a/frontend/public/locales/en-US/translation.toml b/frontend/public/locales/en-US/translation.toml
index b0b68df3f8..8c019fb56d 100644
--- a/frontend/public/locales/en-US/translation.toml
+++ b/frontend/public/locales/en-US/translation.toml
@@ -12856,6 +12856,7 @@ emptyEmail = "Please enter your email"
emptyPassword = "Please enter your password"
emptyUsername = "Please enter your username"
oauthFailed = "OAuth login failed. Please try again."
+openResetFailed = "Could not open your browser to reset your password."
[setup.saas]
title = "Sign in to Stirling"
diff --git a/frontend/src/editor/desktop/components/SetupWizard/SaaSLoginScreen.test.tsx b/frontend/src/editor/desktop/components/SetupWizard/SaaSLoginScreen.test.tsx
new file mode 100644
index 0000000000..276c7c0145
--- /dev/null
+++ b/frontend/src/editor/desktop/components/SetupWizard/SaaSLoginScreen.test.tsx
@@ -0,0 +1,94 @@
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
+import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { MantineProvider } from "@mantine/core";
+import { SaaSLoginScreen } from "@editor/components/SetupWizard/SaaSLoginScreen";
+import { openExternal } from "@editor/platform/openExternal";
+
+vi.mock("react-i18next", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("react-i18next")>()),
+ useTranslation: () => ({
+ t: (key: string, fallback?: string) => fallback ?? key,
+ }),
+}));
+vi.mock("@editor/platform/openExternal", () => ({ openExternal: vi.fn() }));
+vi.mock("@editor/components/SetupWizard/DesktopOAuthButtons", () => ({
+ DesktopOAuthButtons: () => null,
+}));
+
+beforeEach(() => {
+ vi.mocked(openExternal).mockReset();
+ vi.stubEnv("VITE_SAAS_FRONTEND_URL", "https://cloud.example/app");
+});
+afterEach(() => vi.unstubAllEnvs());
+
+function show(error: string | null = null) {
+ render(
+ <MantineProvider>
+ <SaaSLoginScreen
+ serverUrl="https://auth.example"
+ onLogin={vi.fn()}
+ onOAuthSuccess={vi.fn()}
+ onSwitchToSignup={vi.fn()}
+ loading={false}
+ error={error}
+ />
+ </MantineProvider>,
+ );
+}
+
+const forgotPassword = () =>
+ screen.getByRole("button", { name: "Forgot your password?" });
+
+it("opens the web reset page under the configured web path", async () => {
+ vi.mocked(openExternal).mockResolvedValue(undefined);
+ show();
+ fireEvent.click(forgotPassword());
+ await waitFor(() =>
+ expect(openExternal).toHaveBeenCalledWith(
+ "https://cloud.example/app/auth/reset",
+ ),
+ );
+});
+
+it("says so when the system browser cannot open, and clears on retry", async () => {
+ vi.mocked(openExternal)
+ .mockRejectedValueOnce(new Error("Shell unavailable"))
+ .mockResolvedValueOnce(undefined);
+ show();
+ fireEvent.click(forgotPassword());
+ expect(
+ await screen.findByText(
+ "Could not open your browser to reset your password.",
+ ),
+ ).toBeVisible();
+ fireEvent.click(forgotPassword());
+ await waitFor(() => expect(openExternal).toHaveBeenCalledTimes(2));
+ expect(
+ screen.queryByText("Could not open your browser to reset your password."),
+ ).toBeNull();
+});
+
+it("shows the reset failure over an earlier login failure", async () => {
+ vi.mocked(openExternal).mockRejectedValue(new Error("Shell unavailable"));
+ show("Invalid username or password.");
+ expect(screen.getByText("Invalid username or password.")).toBeVisible();
+ fireEvent.click(forgotPassword());
+ expect(
+ await screen.findByText(
+ "Could not open your browser to reset your password.",
+ ),
+ ).toBeVisible();
+ expect(screen.queryByText("Invalid username or password.")).toBeNull();
+});
+
+it("reports a missing web URL instead of opening anything", async () => {
+ vi.stubEnv("VITE_SAAS_FRONTEND_URL", "");
+ show();
+ fireEvent.click(forgotPassword());
+ expect(
+ await screen.findByText(
+ "Could not open your browser to reset your password.",
+ ),
+ ).toBeVisible();
+ expect(openExternal).not.toHaveBeenCalled();
+});
diff --git a/frontend/src/editor/desktop/components/SetupWizard/SaaSLoginScreen.tsx b/frontend/src/editor/desktop/components/SetupWizard/SaaSLoginScreen.tsx
index f340d36e33..db16d54a8d 100644
--- a/frontend/src/editor/desktop/components/SetupWizard/SaaSLoginScreen.tsx
+++ b/frontend/src/editor/desktop/components/SetupWizard/SaaSLoginScreen.tsx
@@ -8,6 +8,8 @@ import { DesktopOAuthButtons } from "@editor/components/SetupWizard/DesktopOAuth
import { SelfHostedLink } from "@editor/components/SetupWizard/SelfHostedLink";
import { UserInfo } from "@editor/services/authService";
import { Button } from "@editor/ui/Button";
+import { openExternal } from "@editor/platform/openExternal";
+import { webPageUrl } from "@editor/utils/webPageUrl";
import "@editor/auth/ui/auth.css";
interface SaaSLoginScreenProps {
@@ -62,7 +64,27 @@ export const SaaSLoginScreen: React.FC<SaaSLoginScreenProps> = ({
setValidationError(errorMessage);
};
- const displayError = error || validationError;
+ // Reset runs on the web app's reset page, which also receives the emailed
+ // link; opening it keeps one copy of the flow instead of a desktop fork.
+ const openPasswordReset = async () => {
+ setValidationError(null);
+ try {
+ await openExternal(
+ webPageUrl(import.meta.env.VITE_SAAS_FRONTEND_URL, "auth/reset"),
+ );
+ } catch {
+ setValidationError(
+ t(
+ "setup.login.error.openResetFailed",
+ "Could not open your browser to reset your password.",
+ ),
+ );
+ }
+ };
+
+ // The local message wins because it is always the newer one: every path that
+ // can set `error` (email submit, OAuth success) clears validationError first.
+ const displayError = validationError || error;
return (
<>
@@ -74,7 +96,10 @@ export const SaaSLoginScreen: React.FC<SaaSLoginScreenProps> = ({
<ErrorMessage error={displayError} />
<DesktopOAuthButtons
- onOAuthSuccess={onOAuthSuccess}
+ onOAuthSuccess={(userInfo) => {
+ setValidationError(null);
+ return onOAuthSuccess(userInfo);
+ }}
onError={handleOAuthError}
isDisabled={loading}
serverUrl={serverUrl}
@@ -106,8 +131,20 @@ export const SaaSLoginScreen: React.FC<SaaSLoginScreenProps> = ({
<div
className="navigation-link-container"
- style={{ marginTop: "0.5rem", textAlign: "right" }}
+ style={{
+ marginTop: "0.5rem",
+ display: "flex",
+ justifyContent: "space-between",
+ }}
>
+ <Button
+ variant="tertiary"
+ onClick={() => void openPasswordReset()}
+ className="navigation-link-button"
+ disabled={loading}
+ >
+ {t("login.forgotPassword", "Forgot your password?")}
+ </Button>
<Button
variant="tertiary"
onClick={() => {
diff --git a/frontend/src/editor/desktop/components/settings/BillingSettingsSection.tsx b/frontend/src/editor/desktop/components/settings/BillingSettingsSection.tsx
index 1e89fbcce5..fce9c25b5a 100644
--- a/frontend/src/editor/desktop/components/settings/BillingSettingsSection.tsx
+++ b/frontend/src/editor/desktop/components/settings/BillingSettingsSection.tsx
@@ -5,6 +5,7 @@ import { Button } from "@editor/ui/Button";
import { Banner } from "@editor/ui/Banner";
import { openExternal } from "@editor/platform/openExternal";
import { connectionModeService } from "@editor/services/connectionModeService";
+import { webPageUrl } from "@editor/utils/webPageUrl";
/** Billing runs on the web because desktop does not ship the processor's billing UI. */
export function BillingSettingsSection({
@@ -26,16 +27,7 @@ export function BillingSettingsSection({
mode === "saas"
? import.meta.env.VITE_SAAS_FRONTEND_URL
: connection.server_config?.url;
- if (!base) throw new Error("Billing destination unavailable");
- const url = new URL(base);
- if (url.protocol !== "https:" && url.protocol !== "http:")
- throw new Error("Invalid billing destination");
- url.pathname = `${url.pathname.replace(/\/+$/, "")}/settings/billing`;
- url.search = "";
- url.hash = "";
- url.username = "";
- url.password = "";
- await openExternal(url.href);
+ await openExternal(webPageUrl(base, "settings/billing"));
} catch {
setFailed(true);
} finally {
diff --git a/frontend/src/editor/desktop/utils/webPageUrl.ts b/frontend/src/editor/desktop/utils/webPageUrl.ts
new file mode 100644
index 0000000000..8cda5c0e48
--- /dev/null
+++ b/frontend/src/editor/desktop/utils/webPageUrl.ts
@@ -0,0 +1,18 @@
+/**
+ * Link to a page of a Stirling web app, for handing to the system browser.
+ * `path` is joined under `base`'s own path, so a sub-path deployment such as
+ * `https://stirling.com/app` keeps its prefix. Query, hash and credentials on
+ * `base` are dropped. Throws when `base` is missing or not http(s).
+ */
+export function webPageUrl(base: string | undefined, path: string): string {
+ if (!base) throw new Error("Web app URL unavailable");
+ const url = new URL(base);
+ if (url.protocol !== "https:" && url.protocol !== "http:")
+ throw new Error("Invalid web app URL");
+ url.pathname = `${url.pathname.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
+ url.search = "";
+ url.hash = "";
+ url.username = "";
+ url.password = "";
+ return url.href;
+}