@devopsplaybook.io/common-web 0.13.0 → 0.14.0-beta.25.2850fe8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +179 -0
- package/components/AuthorizeDeviceCard.vue +575 -0
- package/components/LoginCodeInput.vue +141 -0
- package/components/LoginWithCodeCard.vue +408 -0
- package/composables/useLoginCode.ts +436 -0
- package/package.json +1 -1
- package/services/LoginCodeService.ts +460 -0
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<section class="authorize-device-card" :aria-labelledby="titleId">
|
|
3
|
+
<h2 :id="titleId" class="authorize-device-title">{{ copy.title }}</h2>
|
|
4
|
+
<p class="authorize-device-warning">{{ copy.warning }}</p>
|
|
5
|
+
|
|
6
|
+
<p v-if="loading" class="authorize-device-preparing">
|
|
7
|
+
{{ copy.preparing }}
|
|
8
|
+
</p>
|
|
9
|
+
<p v-else-if="unavailable" class="authorize-device-unavailable">
|
|
10
|
+
{{ copy.unavailable }}
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<form class="authorize-device-form" @submit.prevent="submitCode">
|
|
14
|
+
<LoginCodeInput
|
|
15
|
+
v-model="codeValue"
|
|
16
|
+
:label="copy.codeLabel"
|
|
17
|
+
:length="codeLength"
|
|
18
|
+
:error="codeError ?? undefined"
|
|
19
|
+
:disabled="formDisabled"
|
|
20
|
+
@submit="submitCode"
|
|
21
|
+
/>
|
|
22
|
+
<button
|
|
23
|
+
type="submit"
|
|
24
|
+
class="authorize-device-button authorize-device-button-primary"
|
|
25
|
+
:disabled="formDisabled"
|
|
26
|
+
>
|
|
27
|
+
{{ copy.preview }}
|
|
28
|
+
</button>
|
|
29
|
+
</form>
|
|
30
|
+
|
|
31
|
+
<p v-if="formError" class="authorize-device-error" role="alert">
|
|
32
|
+
{{ formError }}
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
<div v-if="previewResult && !unavailable" class="authorize-device-preview">
|
|
36
|
+
<p class="authorize-device-sign-in">
|
|
37
|
+
{{ copy.willSignInAs }}
|
|
38
|
+
<strong>{{ previewResult.userName }}</strong>
|
|
39
|
+
</p>
|
|
40
|
+
<dl class="authorize-device-details">
|
|
41
|
+
<dt>{{ copy.deviceLabel }}</dt>
|
|
42
|
+
<dd>{{ previewResult.deviceLabel }}</dd>
|
|
43
|
+
<dt>{{ copy.userAgentLabel }}</dt>
|
|
44
|
+
<dd :title="previewResult.userAgent">{{ truncatedUserAgent }}</dd>
|
|
45
|
+
<dt>{{ copy.requestedAt }}</dt>
|
|
46
|
+
<dd>
|
|
47
|
+
<time :datetime="previewResult.createdAt">
|
|
48
|
+
{{ formatDate(previewResult.createdAt) }}
|
|
49
|
+
</time>
|
|
50
|
+
</dd>
|
|
51
|
+
<dt>{{ copy.expiresAt }}</dt>
|
|
52
|
+
<dd>
|
|
53
|
+
<time :datetime="previewResult.expiresAt">
|
|
54
|
+
{{ formatDate(previewResult.expiresAt) }}
|
|
55
|
+
</time>
|
|
56
|
+
</dd>
|
|
57
|
+
</dl>
|
|
58
|
+
|
|
59
|
+
<div v-if="requiresPassword" class="authorize-device-password">
|
|
60
|
+
<label :for="passwordId" class="authorize-device-label">
|
|
61
|
+
{{ copy.password }}
|
|
62
|
+
</label>
|
|
63
|
+
<input
|
|
64
|
+
:id="passwordId"
|
|
65
|
+
v-model="password"
|
|
66
|
+
class="authorize-device-input"
|
|
67
|
+
type="password"
|
|
68
|
+
autocomplete="current-password"
|
|
69
|
+
:disabled="busy"
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<p
|
|
74
|
+
v-if="successMessage"
|
|
75
|
+
class="authorize-device-success"
|
|
76
|
+
role="status"
|
|
77
|
+
aria-live="polite"
|
|
78
|
+
>
|
|
79
|
+
{{ successMessage }}
|
|
80
|
+
</p>
|
|
81
|
+
|
|
82
|
+
<div class="authorize-device-actions">
|
|
83
|
+
<button
|
|
84
|
+
type="button"
|
|
85
|
+
class="authorize-device-button authorize-device-button-primary"
|
|
86
|
+
:disabled="busy || !available"
|
|
87
|
+
@click="approve"
|
|
88
|
+
>
|
|
89
|
+
{{ copy.approve }}
|
|
90
|
+
</button>
|
|
91
|
+
<button
|
|
92
|
+
type="button"
|
|
93
|
+
class="authorize-device-button authorize-device-button-secondary"
|
|
94
|
+
:disabled="busy"
|
|
95
|
+
@click="reset"
|
|
96
|
+
>
|
|
97
|
+
{{ copy.cancel }}
|
|
98
|
+
</button>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
</section>
|
|
102
|
+
</template>
|
|
103
|
+
|
|
104
|
+
<script setup lang="ts">
|
|
105
|
+
import { computed, onMounted, onUnmounted, ref, useId, watch } from "vue";
|
|
106
|
+
import LoginCodeInput from "./LoginCodeInput.vue";
|
|
107
|
+
import {
|
|
108
|
+
LoginCodeError,
|
|
109
|
+
LoginCodeService,
|
|
110
|
+
type LoginCodeApproval,
|
|
111
|
+
type LoginCodeCapabilities,
|
|
112
|
+
type LoginCodeErrorCode,
|
|
113
|
+
type LoginCodePreview,
|
|
114
|
+
} from "../services/LoginCodeService";
|
|
115
|
+
|
|
116
|
+
interface AuthorizeDeviceCardLabels {
|
|
117
|
+
title: string;
|
|
118
|
+
warning: string;
|
|
119
|
+
codeLabel: string;
|
|
120
|
+
preview: string;
|
|
121
|
+
approve: string;
|
|
122
|
+
cancel: string;
|
|
123
|
+
password: string;
|
|
124
|
+
willSignInAs: string;
|
|
125
|
+
deviceLabel: string;
|
|
126
|
+
userAgentLabel: string;
|
|
127
|
+
requestedAt: string;
|
|
128
|
+
expiresAt: string;
|
|
129
|
+
approved: string;
|
|
130
|
+
unavailable: string;
|
|
131
|
+
preparing: string;
|
|
132
|
+
invalidCode: string;
|
|
133
|
+
alreadyUsed: string;
|
|
134
|
+
rateLimited: string;
|
|
135
|
+
passwordRequired: string;
|
|
136
|
+
unauthenticated: string;
|
|
137
|
+
forbidden: string;
|
|
138
|
+
network: string;
|
|
139
|
+
generic: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const DEFAULT_LABELS: AuthorizeDeviceCardLabels = {
|
|
143
|
+
title: "Approve a sign-in",
|
|
144
|
+
warning: "Only approve if you just started a login on that device",
|
|
145
|
+
codeLabel: "Login code",
|
|
146
|
+
preview: "Continue",
|
|
147
|
+
approve: "Approve sign-in",
|
|
148
|
+
cancel: "Cancel",
|
|
149
|
+
password: "Password",
|
|
150
|
+
willSignInAs: "Will sign in as",
|
|
151
|
+
deviceLabel: "Device",
|
|
152
|
+
userAgentLabel: "User agent",
|
|
153
|
+
requestedAt: "Requested",
|
|
154
|
+
expiresAt: "Expires",
|
|
155
|
+
approved: "Sign-in approved",
|
|
156
|
+
unavailable: "Login with a code is unavailable",
|
|
157
|
+
preparing: "Checking availability…",
|
|
158
|
+
invalidCode: "That code is invalid or has expired. Check the code and try again.",
|
|
159
|
+
alreadyUsed: "That code was already used. Ask the other device for a new code.",
|
|
160
|
+
rateLimited: "Too many attempts. Wait a moment and try again.",
|
|
161
|
+
passwordRequired: "Enter your password to approve this sign-in.",
|
|
162
|
+
unauthenticated: "Sign in again to approve this device.",
|
|
163
|
+
forbidden: "This session cannot approve a sign-in.",
|
|
164
|
+
network: "The request could not be completed. Check your connection and try again.",
|
|
165
|
+
generic: "The sign-in could not be approved. Try again.",
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const props = withDefaults(
|
|
169
|
+
defineProps<{
|
|
170
|
+
service?: LoginCodeService;
|
|
171
|
+
labels?: Partial<AuthorizeDeviceCardLabels>;
|
|
172
|
+
}>(),
|
|
173
|
+
{
|
|
174
|
+
service: () => new LoginCodeService(),
|
|
175
|
+
labels: undefined,
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const emit = defineEmits<{
|
|
180
|
+
approved: [result: LoginCodeApproval];
|
|
181
|
+
cancel: [];
|
|
182
|
+
}>();
|
|
183
|
+
|
|
184
|
+
const copy = computed<AuthorizeDeviceCardLabels>(() => ({
|
|
185
|
+
...DEFAULT_LABELS,
|
|
186
|
+
...props.labels,
|
|
187
|
+
}));
|
|
188
|
+
|
|
189
|
+
const uid = useId();
|
|
190
|
+
const titleId = `authorize-device-title-${uid}`;
|
|
191
|
+
const passwordId = `authorize-device-password-${uid}`;
|
|
192
|
+
|
|
193
|
+
const capabilities = ref<LoginCodeCapabilities | null>(null);
|
|
194
|
+
const loading = ref(true);
|
|
195
|
+
const stage = ref<"idle" | "previewing" | "preview" | "approving" | "approved">(
|
|
196
|
+
"idle",
|
|
197
|
+
);
|
|
198
|
+
const codeValue = ref("");
|
|
199
|
+
const password = ref("");
|
|
200
|
+
const previewResult = ref<LoginCodePreview | null>(null);
|
|
201
|
+
const codeError = ref<string | null>(null);
|
|
202
|
+
const formError = ref<string | null>(null);
|
|
203
|
+
const successMessage = ref<string | null>(null);
|
|
204
|
+
|
|
205
|
+
let capabilitiesController: AbortController | null = null;
|
|
206
|
+
let activeController: AbortController | null = null;
|
|
207
|
+
|
|
208
|
+
const available = computed(
|
|
209
|
+
() =>
|
|
210
|
+
!loading.value &&
|
|
211
|
+
capabilities.value !== null &&
|
|
212
|
+
capabilities.value.enabled &&
|
|
213
|
+
capabilities.value.available,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
const unavailable = computed(() => !loading.value && !available.value);
|
|
217
|
+
|
|
218
|
+
const busy = computed(
|
|
219
|
+
() => stage.value === "previewing" || stage.value === "approving",
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const requiresPassword = computed(
|
|
223
|
+
() => capabilities.value?.approveRequiresPassword === true,
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const codeLength = computed(() => {
|
|
227
|
+
const length = capabilities.value?.codeLength;
|
|
228
|
+
return typeof length === "number" && Number.isFinite(length) && length > 0
|
|
229
|
+
? length
|
|
230
|
+
: 8;
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const formDisabled = computed(
|
|
234
|
+
() => !available.value || busy.value || stage.value === "approved",
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const truncatedUserAgent = computed(() => {
|
|
238
|
+
const value = previewResult.value?.userAgent ?? "";
|
|
239
|
+
return value.length > 120 ? value.slice(0, 120) : value;
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
function normalizeCode(value: string): string {
|
|
243
|
+
return value.toUpperCase().replace(/[\s-]/g, "");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function errorCopy(code: LoginCodeErrorCode): string {
|
|
247
|
+
switch (code) {
|
|
248
|
+
case "INVALID_CODE":
|
|
249
|
+
return copy.value.invalidCode;
|
|
250
|
+
case "ALREADY_USED":
|
|
251
|
+
return copy.value.alreadyUsed;
|
|
252
|
+
case "RATE_LIMITED":
|
|
253
|
+
return copy.value.rateLimited;
|
|
254
|
+
case "PASSWORD_REQUIRED":
|
|
255
|
+
return copy.value.passwordRequired;
|
|
256
|
+
case "UNAUTHENTICATED":
|
|
257
|
+
return copy.value.unauthenticated;
|
|
258
|
+
case "FORBIDDEN":
|
|
259
|
+
return copy.value.forbidden;
|
|
260
|
+
case "NETWORK":
|
|
261
|
+
case "TIMEOUT":
|
|
262
|
+
return copy.value.network;
|
|
263
|
+
default:
|
|
264
|
+
return copy.value.generic;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function formatDate(value: string): string {
|
|
269
|
+
const date = new Date(value);
|
|
270
|
+
return Number.isNaN(date.getTime()) ? value : date.toLocaleString();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function abortActive(): void {
|
|
274
|
+
activeController?.abort();
|
|
275
|
+
activeController = null;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function handleRequestError(
|
|
279
|
+
caught: unknown,
|
|
280
|
+
fromStage: "previewing" | "approving",
|
|
281
|
+
): void {
|
|
282
|
+
const failure =
|
|
283
|
+
caught instanceof LoginCodeError
|
|
284
|
+
? caught
|
|
285
|
+
: new LoginCodeError("NETWORK", undefined, { retryable: true });
|
|
286
|
+
const message = errorCopy(failure.code);
|
|
287
|
+
|
|
288
|
+
const keepPreview =
|
|
289
|
+
fromStage === "approving" &&
|
|
290
|
+
previewResult.value !== null &&
|
|
291
|
+
(failure.code === "PASSWORD_REQUIRED" ||
|
|
292
|
+
failure.code === "RATE_LIMITED" ||
|
|
293
|
+
failure.code === "NETWORK" ||
|
|
294
|
+
failure.code === "TIMEOUT");
|
|
295
|
+
|
|
296
|
+
if (keepPreview) {
|
|
297
|
+
stage.value = "preview";
|
|
298
|
+
formError.value = message;
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
stage.value = "idle";
|
|
303
|
+
previewResult.value = null;
|
|
304
|
+
successMessage.value = null;
|
|
305
|
+
if (failure.code === "INVALID_CODE" || failure.code === "ALREADY_USED") {
|
|
306
|
+
codeError.value = message;
|
|
307
|
+
formError.value = null;
|
|
308
|
+
} else {
|
|
309
|
+
formError.value = message;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async function submitCode(): Promise<void> {
|
|
314
|
+
if (!available.value || busy.value || stage.value === "approved") return;
|
|
315
|
+
|
|
316
|
+
const code = normalizeCode(codeValue.value);
|
|
317
|
+
if (code.length !== codeLength.value) {
|
|
318
|
+
codeError.value = copy.value.invalidCode;
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
abortActive();
|
|
323
|
+
const controller = new AbortController();
|
|
324
|
+
activeController = controller;
|
|
325
|
+
stage.value = "previewing";
|
|
326
|
+
codeError.value = null;
|
|
327
|
+
formError.value = null;
|
|
328
|
+
successMessage.value = null;
|
|
329
|
+
|
|
330
|
+
try {
|
|
331
|
+
const result = await props.service.preview(code, {
|
|
332
|
+
signal: controller.signal,
|
|
333
|
+
});
|
|
334
|
+
if (activeController !== controller) return;
|
|
335
|
+
previewResult.value = result;
|
|
336
|
+
stage.value = "preview";
|
|
337
|
+
} catch (caught) {
|
|
338
|
+
if (activeController !== controller) return;
|
|
339
|
+
handleRequestError(caught, "previewing");
|
|
340
|
+
} finally {
|
|
341
|
+
if (activeController === controller) activeController = null;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function approve(): Promise<void> {
|
|
346
|
+
if (stage.value !== "preview" || !available.value) return;
|
|
347
|
+
|
|
348
|
+
if (requiresPassword.value && password.value.trim().length === 0) {
|
|
349
|
+
formError.value = copy.value.passwordRequired;
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
abortActive();
|
|
354
|
+
const controller = new AbortController();
|
|
355
|
+
activeController = controller;
|
|
356
|
+
stage.value = "approving";
|
|
357
|
+
formError.value = null;
|
|
358
|
+
|
|
359
|
+
try {
|
|
360
|
+
const result = await props.service.approve(
|
|
361
|
+
{ code: normalizeCode(codeValue.value), password: password.value || undefined },
|
|
362
|
+
{ signal: controller.signal },
|
|
363
|
+
);
|
|
364
|
+
if (activeController !== controller) return;
|
|
365
|
+
successMessage.value = copy.value.approved;
|
|
366
|
+
stage.value = "approved";
|
|
367
|
+
password.value = "";
|
|
368
|
+
emit("approved", result);
|
|
369
|
+
} catch (caught) {
|
|
370
|
+
if (activeController !== controller) return;
|
|
371
|
+
handleRequestError(caught, "approving");
|
|
372
|
+
} finally {
|
|
373
|
+
if (activeController === controller) activeController = null;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function reset(): void {
|
|
378
|
+
abortActive();
|
|
379
|
+
stage.value = "idle";
|
|
380
|
+
codeValue.value = "";
|
|
381
|
+
password.value = "";
|
|
382
|
+
previewResult.value = null;
|
|
383
|
+
codeError.value = null;
|
|
384
|
+
formError.value = null;
|
|
385
|
+
successMessage.value = null;
|
|
386
|
+
emit("cancel");
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
watch(codeValue, () => {
|
|
390
|
+
if (!previewResult.value && stage.value !== "approved") return;
|
|
391
|
+
abortActive();
|
|
392
|
+
stage.value = "idle";
|
|
393
|
+
previewResult.value = null;
|
|
394
|
+
codeError.value = null;
|
|
395
|
+
formError.value = null;
|
|
396
|
+
successMessage.value = null;
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
onMounted(async () => {
|
|
400
|
+
const controller = new AbortController();
|
|
401
|
+
capabilitiesController = controller;
|
|
402
|
+
try {
|
|
403
|
+
const result = await props.service.capabilities({
|
|
404
|
+
signal: controller.signal,
|
|
405
|
+
});
|
|
406
|
+
if (capabilitiesController !== controller) return;
|
|
407
|
+
capabilities.value = result;
|
|
408
|
+
} catch {
|
|
409
|
+
if (capabilitiesController !== controller) return;
|
|
410
|
+
capabilities.value = null;
|
|
411
|
+
} finally {
|
|
412
|
+
if (capabilitiesController === controller) {
|
|
413
|
+
capabilitiesController = null;
|
|
414
|
+
loading.value = false;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
onUnmounted(() => {
|
|
420
|
+
capabilitiesController?.abort();
|
|
421
|
+
capabilitiesController = null;
|
|
422
|
+
abortActive();
|
|
423
|
+
});
|
|
424
|
+
</script>
|
|
425
|
+
|
|
426
|
+
<style scoped>
|
|
427
|
+
.authorize-device-card {
|
|
428
|
+
max-width: 32rem;
|
|
429
|
+
padding: clamp(var(--space-base, 1rem), 3vw, var(--space-xl, 2rem));
|
|
430
|
+
color: var(--color-text, #171717);
|
|
431
|
+
background: var(--color-surface, #fff);
|
|
432
|
+
border: 1px solid var(--color-border, #d6d6d6);
|
|
433
|
+
border-radius: var(--radius-lg, 0.5rem);
|
|
434
|
+
box-shadow: var(--shadow-sm, 0 1px 2px rgb(0 0 0 / 10%));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.authorize-device-title {
|
|
438
|
+
margin: 0 0 var(--space-sm, 0.5rem);
|
|
439
|
+
font-size: var(--text-xl, 1.25rem);
|
|
440
|
+
line-height: 1.3;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.authorize-device-warning {
|
|
444
|
+
padding: var(--space-sm, 0.5rem) var(--space-base, 1rem);
|
|
445
|
+
margin: 0 0 var(--space-base, 1rem);
|
|
446
|
+
color: var(--color-on-warning, #fff);
|
|
447
|
+
font-size: var(--text-sm, 0.875rem);
|
|
448
|
+
font-weight: 600;
|
|
449
|
+
background: var(--color-warning, #8a5a00);
|
|
450
|
+
border-radius: var(--radius-sm, 0.25rem);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
.authorize-device-preparing,
|
|
454
|
+
.authorize-device-unavailable {
|
|
455
|
+
margin: 0 0 var(--space-base, 1rem);
|
|
456
|
+
color: var(--color-text-muted, #5f6368);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.authorize-device-form {
|
|
460
|
+
display: flex;
|
|
461
|
+
flex-direction: column;
|
|
462
|
+
gap: var(--space-sm, 0.5rem);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.authorize-device-button {
|
|
466
|
+
align-self: flex-start;
|
|
467
|
+
padding: var(--space-sm, 0.5rem) var(--space-base, 1rem);
|
|
468
|
+
font: inherit;
|
|
469
|
+
font-size: var(--text-sm, 0.875rem);
|
|
470
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
471
|
+
cursor: pointer;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
.authorize-device-button:focus-visible {
|
|
475
|
+
outline: 3px solid var(--color-primary, #c62828);
|
|
476
|
+
outline-offset: 2px;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
.authorize-device-button:disabled {
|
|
480
|
+
opacity: 0.6;
|
|
481
|
+
cursor: not-allowed;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
.authorize-device-button-primary {
|
|
485
|
+
color: #fff;
|
|
486
|
+
background: var(--color-primary, #c62828);
|
|
487
|
+
border: 1px solid var(--color-primary, #c62828);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
.authorize-device-button-primary:hover:not(:disabled) {
|
|
491
|
+
background: var(--color-primary-hover, #a61f1f);
|
|
492
|
+
border-color: var(--color-primary-hover, #a61f1f);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
.authorize-device-button-secondary {
|
|
496
|
+
color: var(--color-text, #171717);
|
|
497
|
+
background: var(--color-surface, #fff);
|
|
498
|
+
border: 1px solid var(--color-text-muted, #5f6368);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
.authorize-device-error {
|
|
502
|
+
margin: var(--space-sm, 0.5rem) 0;
|
|
503
|
+
color: var(--color-error, #c62828);
|
|
504
|
+
font-size: var(--text-sm, 0.875rem);
|
|
505
|
+
font-weight: 600;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
.authorize-device-preview {
|
|
509
|
+
padding: var(--space-base, 1rem);
|
|
510
|
+
margin-top: var(--space-base, 1rem);
|
|
511
|
+
background: var(--color-surface-raised, #f5f5f5);
|
|
512
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
.authorize-device-sign-in {
|
|
516
|
+
margin: 0 0 var(--space-sm, 0.5rem);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.authorize-device-details {
|
|
520
|
+
display: grid;
|
|
521
|
+
grid-template-columns: max-content 1fr;
|
|
522
|
+
gap: var(--space-xs, 0.25rem) var(--space-base, 1rem);
|
|
523
|
+
margin: 0 0 var(--space-base, 1rem);
|
|
524
|
+
font-size: var(--text-sm, 0.875rem);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
.authorize-device-details dt {
|
|
528
|
+
color: var(--color-text-muted, #5f6368);
|
|
529
|
+
font-weight: 600;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
.authorize-device-details dd {
|
|
533
|
+
margin: 0;
|
|
534
|
+
overflow-wrap: anywhere;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
.authorize-device-password {
|
|
538
|
+
display: flex;
|
|
539
|
+
flex-direction: column;
|
|
540
|
+
gap: var(--space-xs, 0.25rem);
|
|
541
|
+
margin-bottom: var(--space-base, 1rem);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
.authorize-device-label {
|
|
545
|
+
color: var(--color-text, #171717);
|
|
546
|
+
font-size: var(--text-sm, 0.875rem);
|
|
547
|
+
font-weight: 600;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
.authorize-device-input {
|
|
551
|
+
padding: var(--space-sm, 0.5rem) var(--space-base, 1rem);
|
|
552
|
+
color: var(--color-text, #171717);
|
|
553
|
+
font: inherit;
|
|
554
|
+
background: var(--color-surface, #fff);
|
|
555
|
+
border: 2px solid var(--color-border, #d6d6d6);
|
|
556
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
.authorize-device-input:focus-visible {
|
|
560
|
+
outline: 3px solid var(--color-primary, #c62828);
|
|
561
|
+
outline-offset: 2px;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.authorize-device-success {
|
|
565
|
+
margin: 0 0 var(--space-base, 1rem);
|
|
566
|
+
color: var(--color-success, #2e7d32);
|
|
567
|
+
font-weight: 600;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
.authorize-device-actions {
|
|
571
|
+
display: flex;
|
|
572
|
+
flex-wrap: wrap;
|
|
573
|
+
gap: var(--space-sm, 0.5rem);
|
|
574
|
+
}
|
|
575
|
+
</style>
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="login-code-input">
|
|
3
|
+
<label class="login-code-input-label" :for="inputId">{{ label }}</label>
|
|
4
|
+
<input
|
|
5
|
+
:id="inputId"
|
|
6
|
+
class="login-code-input-field"
|
|
7
|
+
:class="{ 'login-code-input-field-invalid': Boolean(error) }"
|
|
8
|
+
type="text"
|
|
9
|
+
:value="modelValue"
|
|
10
|
+
:maxlength="length"
|
|
11
|
+
autocomplete="off"
|
|
12
|
+
spellcheck="false"
|
|
13
|
+
autocapitalize="characters"
|
|
14
|
+
inputmode="text"
|
|
15
|
+
:disabled="disabled"
|
|
16
|
+
:aria-label="accessibleName"
|
|
17
|
+
:aria-invalid="error ? 'true' : undefined"
|
|
18
|
+
:aria-describedby="error ? errorId : undefined"
|
|
19
|
+
@input="onInput"
|
|
20
|
+
@paste.prevent="onPaste"
|
|
21
|
+
@keydown.enter.prevent="onEnter"
|
|
22
|
+
/>
|
|
23
|
+
<p v-if="error" :id="errorId" class="login-code-input-error" role="alert">
|
|
24
|
+
{{ error }}
|
|
25
|
+
</p>
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script setup lang="ts">
|
|
30
|
+
import { computed, useId } from "vue";
|
|
31
|
+
|
|
32
|
+
const props = withDefaults(
|
|
33
|
+
defineProps<{
|
|
34
|
+
modelValue: string;
|
|
35
|
+
label?: string;
|
|
36
|
+
error?: string;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
length?: number;
|
|
39
|
+
id?: string;
|
|
40
|
+
}>(),
|
|
41
|
+
{
|
|
42
|
+
label: "Login code",
|
|
43
|
+
error: undefined,
|
|
44
|
+
disabled: false,
|
|
45
|
+
length: 8,
|
|
46
|
+
id: undefined,
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const emit = defineEmits<{
|
|
51
|
+
"update:modelValue": [value: string];
|
|
52
|
+
submit: [];
|
|
53
|
+
}>();
|
|
54
|
+
|
|
55
|
+
const generatedId = useId();
|
|
56
|
+
const inputId = computed(() => props.id ?? generatedId);
|
|
57
|
+
const errorId = computed(() => `${inputId.value}-error`);
|
|
58
|
+
|
|
59
|
+
const accessibleName = computed(() => {
|
|
60
|
+
if (!props.modelValue) return props.label;
|
|
61
|
+
const spelled = props.modelValue.split("").join(" ");
|
|
62
|
+
return `${props.label}: ${spelled}`;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
function normalize(value: string): string {
|
|
66
|
+
return value
|
|
67
|
+
.toUpperCase()
|
|
68
|
+
.replace(/[\s-]/g, "")
|
|
69
|
+
.slice(0, props.length);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function onInput(event: Event): void {
|
|
73
|
+
const target = event.target as HTMLInputElement;
|
|
74
|
+
const normalized = normalize(target.value);
|
|
75
|
+
// Keep the DOM in sync when the normalized value equals the current model
|
|
76
|
+
// (for example a rejected digit), where Vue would skip the re-render.
|
|
77
|
+
if (target.value !== normalized) target.value = normalized;
|
|
78
|
+
emit("update:modelValue", normalized);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function onPaste(event: ClipboardEvent): void {
|
|
82
|
+
const target = event.target as HTMLInputElement;
|
|
83
|
+
const text = event.clipboardData?.getData("text") ?? "";
|
|
84
|
+
const normalized = normalize(`${target.value}${text}`);
|
|
85
|
+
target.value = normalized;
|
|
86
|
+
emit("update:modelValue", normalized);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function onEnter(): void {
|
|
90
|
+
if (normalize(props.modelValue).length === props.length) emit("submit");
|
|
91
|
+
}
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<style scoped>
|
|
95
|
+
.login-code-input {
|
|
96
|
+
display: flex;
|
|
97
|
+
flex-direction: column;
|
|
98
|
+
gap: var(--space-xs, 0.25rem);
|
|
99
|
+
margin-bottom: var(--space-base, 1rem);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.login-code-input-label {
|
|
103
|
+
color: var(--color-text, #171717);
|
|
104
|
+
font-size: var(--text-sm, 0.875rem);
|
|
105
|
+
font-weight: 600;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.login-code-input-field {
|
|
109
|
+
width: 100%;
|
|
110
|
+
padding: var(--space-sm, 0.5rem) var(--space-base, 1rem);
|
|
111
|
+
color: var(--color-text, #171717);
|
|
112
|
+
font-family: ui-monospace, "SFMono-Regular", "Consolas", monospace;
|
|
113
|
+
font-size: var(--text-xl, 1.25rem);
|
|
114
|
+
letter-spacing: 0.2em;
|
|
115
|
+
text-transform: uppercase;
|
|
116
|
+
background: var(--color-surface, #fff);
|
|
117
|
+
border: 2px solid var(--color-border, #d6d6d6);
|
|
118
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.login-code-input-field:focus-visible {
|
|
122
|
+
outline: 3px solid var(--color-primary, #c62828);
|
|
123
|
+
outline-offset: 2px;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.login-code-input-field-invalid {
|
|
127
|
+
border-color: var(--color-error, #c62828);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.login-code-input-field:disabled {
|
|
131
|
+
color: var(--color-text-muted, #5f6368);
|
|
132
|
+
background: var(--color-surface-raised, #f5f5f5);
|
|
133
|
+
cursor: not-allowed;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.login-code-input-error {
|
|
137
|
+
margin: 0;
|
|
138
|
+
color: var(--color-error, #c62828);
|
|
139
|
+
font-size: var(--text-sm, 0.875rem);
|
|
140
|
+
}
|
|
141
|
+
</style>
|