From 6d654f666f02d48ecd3b255fd78bc4f49bcdef9b Mon Sep 17 00:00:00 2001 From: Wanjohi Date: Fri, 2 Oct 2026 05:55:44 +0300 Subject: [PATCH] fix(auth): accept a device code typed with its dash A device code is shown as BCDF-3467 and will be typed or pasted that way. The field allowed exactly 8 characters, so a correct code was cut to BCDF-346 before the server, which ignores separators, ever saw it. A grouped code's field now has room for its separators and a pattern that allows a dash or a space between groups, and the device code is declared as two groups of four. --- packages/auth/src/ui/issuer.ts | 1 + packages/auth/src/ui/render.tsx | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/auth/src/ui/issuer.ts b/packages/auth/src/ui/issuer.ts index 4a42fae4..5cbe7e09 100644 --- a/packages/auth/src/ui/issuer.ts +++ b/packages/auth/src/ui/issuer.ts @@ -61,6 +61,7 @@ export const IssuerScreens = { name: 'user_code', label: 'Enter the code shown in the app', length, + group: 4, autocomplete: 'off', autofocus: true } diff --git a/packages/auth/src/ui/render.tsx b/packages/auth/src/ui/render.tsx index e6e579b8..70fadd9f 100644 --- a/packages/auth/src/ui/render.tsx +++ b/packages/auth/src/ui/render.tsx @@ -234,6 +234,15 @@ function Input(props: { field: Field }) { } if (field.kind === 'segments') { + // A grouped code is shown with a separator, `BCDF-3467`, and will be + // typed or pasted the way it was read. Room for the separators, and a + // pattern that allows them, or the box truncates a correct code to + // `BCDF-346` before the server — which ignores them — ever sees it. + const char = field.numeric ? '[0-9]' : '[A-Za-z0-9]'; + const groups = field.group && field.group > 0 ? Math.ceil(field.length / field.group) : 1; + const sizes = Array.from({ length: groups }, (_, i) => + Math.min(field.group ?? field.length, field.length - i * (field.group ?? field.length)) + ); return ( `${char}{${n}}`).join('[\\- ]?')} + size={field.length + groups - 1} required spellcheck={false} autocapitalize="characters"