Skip to content

Open-source document signature platform. Not affiliated with DocuSign.

TypeScript

Sign out before "Log in as someone else" on the setup page

Claudeb4e51ef70d32
diff --git a/e2e/signing-flow.spec.ts b/e2e/signing-flow.spec.ts
index 176c401..b484fb1 100644
--- a/e2e/signing-flow.spec.ts
+++ b/e2e/signing-flow.spec.ts
@@ -361,6 +361,27 @@ test("a new install is set up, a sender sends a PDF and a recipient signs it", a
).toBe(401);
await anonymousContext.close();
+ // Someone signed in to the wrong account is offered a way to switch.
+ // The login page sends signed-in visitors to the dashboard, so the
+ // link has to end the session before going there.
+ const wrongAccountContext = await browser.newContext();
+ const wrongAccountPage = await wrongAccountContext.newPage();
+
+ await wrongAccountPage.goto("/login");
+ await wrongAccountPage.getByLabel("Email").fill(senderEmail);
+ await wrongAccountPage.getByLabel("Password").fill(PASSWORD);
+ await wrongAccountPage.getByRole("button", { name: "Log in" }).click();
+ await expect(wrongAccountPage).toHaveURL(/\/dashboard$/);
+ await wrongAccountPage.goto("/setup");
+ await wrongAccountPage
+ .getByRole("button", { name: "Log in as someone else" })
+ .click();
+ await expect(wrongAccountPage).toHaveURL(/\/login$/);
+ await expect(
+ wrongAccountPage.getByRole("button", { name: "Log in" }),
+ ).toBeVisible();
+ await wrongAccountContext.close();
+
expect(
(await page.request.post("/api/setup", { data: claim })).status(),
).toBe(403);
diff --git a/src/components/setup/setup-shell.tsx b/src/components/setup/setup-shell.tsx
index 95b4a3a..75e7b00 100644
--- a/src/components/setup/setup-shell.tsx
+++ b/src/components/setup/setup-shell.tsx
@@ -1,6 +1,6 @@
"use client";
-import Link from "next/link";
+import { useRouter } from "next/navigation";
import {
useState,
type ChangeEvent,
@@ -11,6 +11,7 @@ import {
import { Brand } from "@/components/layout/brand";
import { PublicLegalFooter } from "@/components/layout/public-legal-links";
import { FieldShell, ShellButton } from "@/components/shared/form-shell";
+import { authClient } from "@/lib/auth/client";
import type { SetupFieldName, SetupView } from "@/lib/setup";
import { getEmailDomain, suggestSignupPolicy } from "@/lib/signup-policy";
@@ -206,10 +207,25 @@ function SetupForm({
const [errors, setErrors] = useState<SetupErrors>({});
const [bannerMessage, setBannerMessage] = useState<string | null>(null);
const [isSubmitting, setIsSubmitting] = useState(false);
+ const [isSwitchingAccount, setIsSwitchingAccount] = useState(false);
+ const router = useRouter();
const isCreate = view.view === "create";
const requiresToken = isCreate ? view.requiresToken : true;
const asksForSender = isCreate && !view.senderAddressFromEnv;
+ async function handleSwitchAccount() {
+ if (isSwitchingAccount) {
+ return;
+ }
+
+ setIsSwitchingAccount(true);
+
+ // The login page sends anyone who is signed in on to the dashboard, so
+ // the current session has to end before it will show its form.
+ await authClient.signOut().catch(() => undefined);
+ router.push("/login");
+ }
+
function handleChange(field: SetupFieldName) {
return (event: ChangeEvent<HTMLInputElement>) => {
const nextValue = event.target.value;
@@ -400,12 +416,14 @@ function SetupForm({
{!isCreate ? (
<p className="border-t border-(--border) pt-5 text-sm text-muted-foreground">
Not the right account?{" "}
- <Link
- className="font-semibold text-(--fg) transition hover:text-(--accent)"
- href="/login"
+ <button
+ className="cursor-pointer font-semibold text-(--fg) transition hover:text-(--accent) disabled:cursor-default disabled:opacity-60"
+ disabled={isSwitchingAccount}
+ onClick={handleSwitchAccount}
+ type="button"
>
Log in as someone else
- </Link>
+ </button>
</p>
) : null}
</div>