A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
fix: retain verification field focus on navigation
Amruth Pillaif4c96be20756
diff --git a/apps/web/src/components/layout/navigation-focus.test.tsx b/apps/web/src/components/layout/navigation-focus.test.tsxindex d3a91ac99..1c976ed86 100644--- a/apps/web/src/components/layout/navigation-focus.test.tsx+++ b/apps/web/src/components/layout/navigation-focus.test.tsx@@ -112,3 +112,60 @@ it.each([undefined, "low", "high"] as const)(expect(field).toHaveFocus();},);++it("focuses the primary verification field instead of its heading", async () => {+ const root = createRootRoute({+ component: () => (+ <>+ <NavigationFocus />+ <Outlet />+ </>+ ),+ });+ const ordinary = createRoute({+ getParentRoute: () => root,+ path: "/ordinary",+ component: () => (+ <main>+ <h1>Ordinary</h1>+ <input aria-label="Ordinary field" />+ </main>+ ),+ });+ const code = createRoute({+ getParentRoute: () => root,+ path: "/code",+ component: () => (+ <main>+ <h1>Code heading</h1>+ <div data-route-focus>+ <input aria-label="Code" />+ </div>+ </main>+ ),+ });+ const backup = createRoute({+ getParentRoute: () => root,+ path: "/backup",+ component: () => (+ <main>+ <h1>Backup heading</h1>+ <div data-route-focus>+ <input aria-label="Backup code" />+ </div>+ </main>+ ),+ });+ const router = createRouter({+ routeTree: root.addChildren([ordinary, code, backup]),+ history: createMemoryHistory({ initialEntries: ["/ordinary"] }),+ });+ render(<RouterProvider router={router} />);+ await waitFor(() => expect(screen.getByRole("heading", { name: "Ordinary" })).toHaveFocus());+ await act(() => router.navigate({ to: "/code" }));+ await waitFor(() => expect(screen.getByRole("textbox", { name: "Code" })).toHaveFocus());+ await act(() => router.navigate({ to: "/backup" }));+ await waitFor(() => expect(screen.getByRole("textbox", { name: "Backup code" })).toHaveFocus());+ await act(() => router.navigate({ to: "/ordinary" }));+ await waitFor(() => expect(screen.getByRole("heading", { name: "Ordinary" })).toHaveFocus());+});diff --git a/apps/web/src/components/layout/navigation-focus.tsx b/apps/web/src/components/layout/navigation-focus.tsxindex 98eab2f53..ef67aafb6 100644--- a/apps/web/src/components/layout/navigation-focus.tsx+++ b/apps/web/src/components/layout/navigation-focus.tsx@@ -14,6 +14,7 @@ export function NavigationFocus() {)return;const target =+ document.querySelector<HTMLElement>("[data-route-focus] input") ??document.querySelector<HTMLElement>("main h1, h1") ??document.querySelector<HTMLElement>("main, #main-content");if (!target) return;diff --git a/apps/web/src/features/auth/pages/verify-2fa.tsx b/apps/web/src/features/auth/pages/verify-2fa.tsxindex 0ded6e00c..e3fe4d858 100644--- a/apps/web/src/features/auth/pages/verify-2fa.tsx+++ b/apps/web/src/features/auth/pages/verify-2fa.tsx@@ -126,6 +126,7 @@ function TwoFactorVerificationPage({ backupCode = false }: TwoFactorVerification{(field) => (<FormItemref={codeRef}+ data-route-focusclassName="justify-self-center"hasError={field.state.meta.isTouched && field.state.meta.errors.length > 0}>diff --git a/docs/guides/signing-in.mdx b/docs/guides/signing-in.mdxindex b5c44490f..1940d0ea9 100644--- a/docs/guides/signing-in.mdx+++ b/docs/guides/signing-in.mdx@@ -92,7 +92,7 @@ The first box has focus, so you can start typing straight away. A wrong code is<Frame caption="Enter the current authenticator code"><imgsrc="/images/guides/signing-in/two-factor-code.webp"- alt="Two-step verification sign-in page with six empty code boxes and Lost access to your authenticator"+ alt="Two-step verification at phone width with the first of six empty code boxes focused, Trust this device for 30 days and Lost access to your authenticator"/></Frame>@@ -100,12 +100,17 @@ The first box has focus, so you can start typing straight away. A wrong code isIf you don't have your authenticator app, select **Lost access to your authenticator?**, enter one of the backup codes you saved when you turned on two-step verification, and select **Verify**.+The backup-code field has focus when the page opens, so you can type straight away.+Each backup code works once. You can paste it as shown, including the hyphen, or type the two groups together (`K7QXM-4PZR2` or `K7QXM4PZR2`). Codes made since November 2026 use capitals without look-alike characters, and you can type them in lower case. Older codes mix capitals and lower case: type those exactly as saved.If you've lost your backup codes too, select **No backup codes either?** If you never verified your email address, a password reset turns two-step verification off. Otherwise a reset keeps it on, so ask the person who runs the server to turn it off for your account, then sign in and set it up again.<Frame caption="Use one backup code if your authenticator is unavailable">- <img src="/images/guides/signing-in/backup-code.webp" alt="Backup code sign-in page with an empty code field" />+ <img+ src="/images/guides/signing-in/backup-code.webp"+ alt="Backup code sign-in at phone width with the empty code field focused and Trust this device for 30 days"+ /></Frame>## Sign outdiff --git a/docs/images/guides/signing-in/backup-code.webp b/docs/images/guides/signing-in/backup-code.webpindex 625f3ac70..f7ff6b24a 100644Binary files a/docs/images/guides/signing-in/backup-code.webp and b/docs/images/guides/signing-in/backup-code.webp differdiff --git a/docs/images/guides/signing-in/two-factor-code.webp b/docs/images/guides/signing-in/two-factor-code.webpindex f2abe420e..5cef156d3 100644Binary files a/docs/images/guides/signing-in/two-factor-code.webp and b/docs/images/guides/signing-in/two-factor-code.webp differdiff --git a/tests/e2e/specs/two-factor-focus.spec.ts b/tests/e2e/specs/two-factor-focus.spec.tsnew file mode 100644index 000000000..002ec6d20--- /dev/null+++ b/tests/e2e/specs/two-factor-focus.spec.ts@@ -0,0 +1,91 @@+import type { Page } from "@playwright/test";+import { createHmac } from "node:crypto";+import { expect, test } from "../fixtures/test";++test.use({ trace: "off", screenshot: "off", video: "off" });++function authenticatorCode(secret: string) {+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";+ const bits = [...secret.toUpperCase().replaceAll("=", "")]+ .map((char) => alphabet.indexOf(char).toString(2).padStart(5, "0"))+ .join("");+ const key = Buffer.from(+ Array.from({ length: Math.floor(bits.length / 8) }, (_, index) =>+ Number.parseInt(bits.slice(index * 8, index * 8 + 8), 2),+ ),+ );+ const counter = Buffer.alloc(8);+ counter.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 30_000)));+ const hash = createHmac("sha1", key).update(counter).digest();+ const offset = hash.readUInt8(hash.length - 1) & 15;+ return ((hash.readUInt32BE(offset) & 0x7fffffff) % 1_000_000).toString().padStart(6, "0");+}++async function routeFocusSettled(page: Page) {+ await page.evaluate(+ () => new Promise<void>((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))),+ );+}++test("two-step and backup verification receive typing after sign-in navigation", async ({+ authPage: page,+ account,+}, info) => {+ const headers = { origin: String(info.project.use.baseURL) };+ const enabled = await page.request.post("/api/auth/two-factor/enable", {+ headers,+ data: { password: account.password },+ });+ expect(enabled.status()).toBe(200);+ const setup = (await enabled.json()) as { totpURI: string; backupCodes: string[] };+ const backupCode = setup.backupCodes[0];+ if (!backupCode) throw new Error("Authenticator setup has no backup code.");+ const secret = new URL(setup.totpURI).searchParams.get("secret");+ if (!secret) throw new Error("Authenticator setup has no secret.");+ const verified = await page.request.post("/api/auth/two-factor/verify-totp", {+ headers,+ data: { code: authenticatorCode(secret) },+ });+ expect(verified.status()).toBe(200);+ try {+ await page.setViewportSize({ width: 390, height: 844 });+ await page.goto("/dashboard/settings/account");+ await page.getByRole("button", { name: "Sign out", exact: true }).click();+ await expect(page).toHaveURL(/\/$/);+ await page.goto("/auth/login");+ await page.getByLabel("Email or username", { exact: true }).fill(account.email);+ await page.getByLabel("Password", { exact: true }).fill(account.password);+ await page.getByRole("button", { name: "Sign in", exact: true }).click();+ await expect(page).toHaveURL(/\/auth\/verify-2fa/);+ const digits = page.locator('[data-slot="otp-field-input"]');+ await expect(digits).toHaveCount(6);+ await routeFocusSettled(page);+ await expect(digits.first()).toBeFocused();+ const bounds = await digits.first().boundingBox();+ expect(bounds?.width).toBeGreaterThanOrEqual(44);+ expect(bounds?.height).toBeGreaterThanOrEqual(44);+ await page.screenshot({ path: info.outputPath("two-step-page.png"), animations: "disabled" });+ await page.keyboard.type("12");+ expect(await digits.evaluateAll((nodes) => nodes.map((node) => (node as HTMLInputElement).value).join(""))).toBe(+ "12",+ );+ await page.getByRole("link", { name: "Lost access to your authenticator?", exact: true }).click();+ const backup = page.getByRole("textbox", { name: "Backup code", exact: true });+ await expect(backup).toBeVisible();+ await routeFocusSettled(page);+ await expect(backup).toBeFocused();+ await page.screenshot({ path: info.outputPath("backup-code-page.png"), animations: "disabled" });+ await page.keyboard.type(backupCode.toLowerCase().replaceAll("-", ""));+ await page.getByRole("button", { name: "Verify", exact: true }).click();+ await expect(page).toHaveURL(/\/dashboard/);+ expect((await page.request.get("/api/openapi/resumes")).status()).toBe(200);+ } finally {+ // Keep one-time codes out of Playwright's failure DOM context as well as traces and videos.+ if (!page.isClosed())+ await page.locator("input").evaluateAll((nodes) =>+ nodes.forEach((node) => {+ if (node instanceof HTMLInputElement) node.value = "";+ }),+ );+ }+});