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"