mirror of
https://github.com/nestriness/nestri.git
synced 2026-11-23 07:29:51 +02:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<input
|
||||
data-component="input"
|
||||
@@ -243,11 +252,11 @@ function Input(props: { field: Field }) {
|
||||
aria-label={field.label}
|
||||
placeholder={field.label}
|
||||
minLength={field.length}
|
||||
maxLength={field.length}
|
||||
maxLength={field.length + groups - 1}
|
||||
// Whole and well-formed, or `:invalid` — which is what the stylesheet
|
||||
// dims the button on. `minLength` alone is not checked until edited.
|
||||
pattern={`${field.numeric ? '[0-9]' : '[A-Za-z0-9]'}{${field.length}}`}
|
||||
size={field.length}
|
||||
pattern={sizes.map((n) => `${char}{${n}}`).join('[\\- ]?')}
|
||||
size={field.length + groups - 1}
|
||||
required
|
||||
spellcheck={false}
|
||||
autocapitalize="characters"
|
||||
|
||||
Reference in New Issue
Block a user