@terreno/ui 57.19.2 → 57.20.0
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/.ai/guidelines/core.md +1 -1
- package/CHANGELOG.md +393 -0
- package/dist/Accordion.d.ts.map +1 -1
- package/dist/Accordion.js +3 -3
- package/dist/Accordion.js.map +1 -1
- package/dist/Avatar.d.ts.map +1 -1
- package/dist/Avatar.js +3 -1
- package/dist/Avatar.js.map +1 -1
- package/dist/Box.d.ts.map +1 -1
- package/dist/Box.js +38 -2
- package/dist/Box.js.map +1 -1
- package/dist/Card.js +2 -2
- package/dist/Card.js.map +1 -1
- package/dist/Common.d.ts +120 -7
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.d.ts +1 -1
- package/dist/ConsentFormScreen.d.ts.map +1 -1
- package/dist/ConsentFormScreen.js +13 -4
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/DateTimeField.d.ts.map +1 -1
- package/dist/DateTimeField.js +5 -3
- package/dist/DateTimeField.js.map +1 -1
- package/dist/Field.d.ts.map +1 -1
- package/dist/Field.js +2 -0
- package/dist/Field.js.map +1 -1
- package/dist/FormContainer.d.ts +68 -0
- package/dist/FormContainer.d.ts.map +1 -0
- package/dist/FormContainer.js +79 -0
- package/dist/FormContainer.js.map +1 -0
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +2 -1
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts +1 -1
- package/dist/Heading.d.ts.map +1 -1
- package/dist/Heading.js +5 -2
- package/dist/Heading.js.map +1 -1
- package/dist/Icon.d.ts +4 -0
- package/dist/Icon.d.ts.map +1 -1
- package/dist/Icon.js +43 -2
- package/dist/Icon.js.map +1 -1
- package/dist/LabeledCheckBox.d.ts +22 -0
- package/dist/LabeledCheckBox.d.ts.map +1 -0
- package/dist/LabeledCheckBox.js +30 -0
- package/dist/LabeledCheckBox.js.map +1 -0
- package/dist/ListDetailLayout.d.ts +36 -0
- package/dist/ListDetailLayout.d.ts.map +1 -0
- package/dist/ListDetailLayout.js +153 -0
- package/dist/ListDetailLayout.js.map +1 -0
- package/dist/MarkdownEditor.d.ts.map +1 -1
- package/dist/MarkdownEditor.js +2 -1
- package/dist/MarkdownEditor.js.map +1 -1
- package/dist/MediaQuery.d.ts +1 -1
- package/dist/MediaQuery.d.ts.map +1 -1
- package/dist/MediaQuery.js +1 -1
- package/dist/MediaQuery.js.map +1 -1
- package/dist/OtpField.d.ts +60 -0
- package/dist/OtpField.d.ts.map +1 -0
- package/dist/OtpField.js +154 -0
- package/dist/OtpField.js.map +1 -0
- package/dist/ProvisionalConsentSigner.d.ts +21 -0
- package/dist/ProvisionalConsentSigner.d.ts.map +1 -0
- package/dist/ProvisionalConsentSigner.js +199 -0
- package/dist/ProvisionalConsentSigner.js.map +1 -0
- package/dist/ResponsiveBreakpoint.d.ts +5 -0
- package/dist/ResponsiveBreakpoint.d.ts.map +1 -1
- package/dist/ResponsiveBreakpoint.js +7 -0
- package/dist/ResponsiveBreakpoint.js.map +1 -1
- package/dist/SocialLoginButton.d.ts +10 -0
- package/dist/SocialLoginButton.d.ts.map +1 -1
- package/dist/SocialLoginButton.js +26 -8
- package/dist/SocialLoginButton.js.map +1 -1
- package/dist/SplitPage.d.ts +11 -0
- package/dist/SplitPage.d.ts.map +1 -1
- package/dist/SplitPage.js +11 -5
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts.map +1 -1
- package/dist/SplitPage.native.js +3 -1
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/SyncStatusBanner.d.ts +7 -1
- package/dist/SyncStatusBanner.d.ts.map +1 -1
- package/dist/SyncStatusBanner.js +20 -4
- package/dist/SyncStatusBanner.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +44 -10
- package/dist/TextField.js.map +1 -1
- package/dist/fieldElements/FieldError.d.ts.map +1 -1
- package/dist/fieldElements/FieldError.js +1 -1
- package/dist/fieldElements/FieldError.js.map +1 -1
- package/dist/index.d.ts +19 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +3 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +2 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/login/LastUsedBadge.d.ts +14 -0
- package/dist/login/LastUsedBadge.d.ts.map +1 -0
- package/dist/login/LastUsedBadge.js +23 -0
- package/dist/login/LastUsedBadge.js.map +1 -0
- package/dist/login/LoginAccountCard.d.ts +38 -0
- package/dist/login/LoginAccountCard.d.ts.map +1 -0
- package/dist/login/LoginAccountCard.js +72 -0
- package/dist/login/LoginAccountCard.js.map +1 -0
- package/dist/login/LoginAccountList.d.ts +33 -0
- package/dist/login/LoginAccountList.d.ts.map +1 -0
- package/dist/login/LoginAccountList.js +30 -0
- package/dist/login/LoginAccountList.js.map +1 -0
- package/dist/login/LoginScreen.d.ts +4 -4
- package/dist/login/LoginScreen.d.ts.map +1 -1
- package/dist/login/LoginScreen.js +294 -13
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/login/OutlinePill.d.ts +28 -0
- package/dist/login/OutlinePill.d.ts.map +1 -0
- package/dist/login/OutlinePill.js +48 -0
- package/dist/login/OutlinePill.js.map +1 -0
- package/dist/login/TwoFactorChallengeScreen.d.ts +26 -0
- package/dist/login/TwoFactorChallengeScreen.d.ts.map +1 -0
- package/dist/login/TwoFactorChallengeScreen.js +139 -0
- package/dist/login/TwoFactorChallengeScreen.js.map +1 -0
- package/dist/login/loginMethods.d.ts +27 -0
- package/dist/login/loginMethods.d.ts.map +1 -0
- package/dist/login/loginMethods.js +37 -0
- package/dist/login/loginMethods.js.map +1 -0
- package/dist/login/loginTypes.d.ts +202 -5
- package/dist/login/loginTypes.d.ts.map +1 -1
- package/dist/pdfHtmlTemplate.d.ts +17 -0
- package/dist/pdfHtmlTemplate.d.ts.map +1 -1
- package/dist/pdfHtmlTemplate.js +78 -0
- package/dist/pdfHtmlTemplate.js.map +1 -1
- package/dist/security/AccountSecurityScreen.d.ts +10 -0
- package/dist/security/AccountSecurityScreen.d.ts.map +1 -0
- package/dist/security/AccountSecurityScreen.js +50 -0
- package/dist/security/AccountSecurityScreen.js.map +1 -0
- package/dist/security/LinkedAccountsCard.d.ts +32 -0
- package/dist/security/LinkedAccountsCard.d.ts.map +1 -0
- package/dist/security/LinkedAccountsCard.js +145 -0
- package/dist/security/LinkedAccountsCard.js.map +1 -0
- package/dist/security/PasskeysCard.d.ts +39 -0
- package/dist/security/PasskeysCard.d.ts.map +1 -0
- package/dist/security/PasskeysCard.js +168 -0
- package/dist/security/PasskeysCard.js.map +1 -0
- package/dist/security/PasswordCard.d.ts +32 -0
- package/dist/security/PasswordCard.d.ts.map +1 -0
- package/dist/security/PasswordCard.js +198 -0
- package/dist/security/PasswordCard.js.map +1 -0
- package/dist/security/SessionsCard.d.ts +39 -0
- package/dist/security/SessionsCard.d.ts.map +1 -0
- package/dist/security/SessionsCard.js +168 -0
- package/dist/security/SessionsCard.js.map +1 -0
- package/dist/security/TwoFactorSettingsCard.d.ts +55 -0
- package/dist/security/TwoFactorSettingsCard.d.ts.map +1 -0
- package/dist/security/TwoFactorSettingsCard.js +458 -0
- package/dist/security/TwoFactorSettingsCard.js.map +1 -0
- package/dist/security/securityMethods.d.ts +40 -0
- package/dist/security/securityMethods.d.ts.map +1 -0
- package/dist/security/securityMethods.js +66 -0
- package/dist/security/securityMethods.js.map +1 -0
- package/dist/security/securityTypes.d.ts +467 -0
- package/dist/security/securityTypes.d.ts.map +1 -0
- package/dist/security/securityTypes.js +2 -0
- package/dist/security/securityTypes.js.map +1 -0
- package/dist/security/userAgent.d.ts +26 -0
- package/dist/security/userAgent.d.ts.map +1 -0
- package/dist/security/userAgent.js +80 -0
- package/dist/security/userAgent.js.map +1 -0
- package/dist/signUp/OAuthButtons.d.ts +28 -5
- package/dist/signUp/OAuthButtons.d.ts.map +1 -1
- package/dist/signUp/OAuthButtons.js +44 -5
- package/dist/signUp/OAuthButtons.js.map +1 -1
- package/dist/signUp/SignUpScreen.d.ts.map +1 -1
- package/dist/signUp/SignUpScreen.js +50 -5
- package/dist/signUp/SignUpScreen.js.map +1 -1
- package/dist/signUp/signUpTypes.d.ts +21 -1
- package/dist/signUp/signUpTypes.d.ts.map +1 -1
- package/dist/useConsentForms.d.ts +9 -0
- package/dist/useConsentForms.d.ts.map +1 -1
- package/dist/useConsentForms.js +18 -0
- package/dist/useConsentForms.js.map +1 -1
- package/dist/useProvisionalConsent.d.ts +124 -0
- package/dist/useProvisionalConsent.d.ts.map +1 -0
- package/dist/useProvisionalConsent.js +79 -0
- package/dist/useProvisionalConsent.js.map +1 -0
- package/package.json +3 -2
- package/src/Accordion.test.tsx +5 -0
- package/src/Accordion.tsx +3 -8
- package/src/AreaChart.test.tsx +15 -0
- package/src/Avatar.test.tsx +8 -0
- package/src/Avatar.tsx +2 -0
- package/src/BarChart.test.tsx +15 -0
- package/src/Box.test.tsx +61 -1
- package/src/Box.tsx +44 -2
- package/src/Card.tsx +2 -2
- package/src/Common.ts +134 -7
- package/src/ConsentFormScreen.test.tsx +84 -0
- package/src/ConsentFormScreen.tsx +28 -4
- package/src/DateTimeField.tsx +5 -3
- package/src/DonutChart.test.tsx +15 -0
- package/src/Field.tsx +2 -0
- package/src/FilePickerButton.test.tsx +35 -0
- package/src/FormContainer.test.tsx +242 -0
- package/src/FormContainer.tsx +177 -0
- package/src/GPTChat.test.tsx +16 -0
- package/src/GPTChat.tsx +8 -2
- package/src/Heading.test.tsx +14 -0
- package/src/Heading.tsx +6 -1
- package/src/Icon.test.tsx +52 -1
- package/src/Icon.tsx +92 -3
- package/src/IconButton.test.tsx +85 -0
- package/src/LabeledCheckBox.test.tsx +45 -0
- package/src/LabeledCheckBox.tsx +89 -0
- package/src/ListDetailLayout.tsx +247 -0
- package/src/MarkdownEditor.tsx +2 -1
- package/src/MediaQuery.ts +1 -0
- package/src/OtpField.test.tsx +280 -0
- package/src/OtpField.tsx +307 -0
- package/src/ProvisionalConsentSigner.test.tsx +625 -0
- package/src/ProvisionalConsentSigner.tsx +423 -0
- package/src/ResponsiveBreakpoint.test.tsx +7 -0
- package/src/ResponsiveBreakpoint.tsx +14 -0
- package/src/RootImportRegression.test.tsx +3 -0
- package/src/SocialLoginButton.test.tsx +14 -0
- package/src/SocialLoginButton.tsx +51 -7
- package/src/SplitPage.native.tsx +3 -1
- package/src/SplitPage.tsx +11 -5
- package/src/SyncStatusBanner.test.tsx +61 -4
- package/src/SyncStatusBanner.tsx +29 -3
- package/src/TextField.test.tsx +150 -0
- package/src/TextField.tsx +66 -8
- package/src/__snapshots__/AddressField.test.tsx.snap +12 -0
- package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +15 -0
- package/src/__snapshots__/Avatar.test.tsx.snap +1 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +3 -0
- package/src/__snapshots__/EmailField.test.tsx.snap +6 -0
- package/src/__snapshots__/Field.test.tsx.snap +37 -0
- package/src/__snapshots__/HeightField.test.tsx.snap +2 -0
- package/src/__snapshots__/MobileAddressAutoComplete.test.tsx.snap +3 -0
- package/src/__snapshots__/NumberField.test.tsx.snap +3 -0
- package/src/__snapshots__/PhoneNumberField.test.tsx.snap +12 -0
- package/src/__snapshots__/Slider.test.tsx.snap +1 -0
- package/src/__snapshots__/SocialLoginButton.test.tsx.snap +43 -22
- package/src/__snapshots__/TapToEdit.test.tsx.snap +3 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +17 -1
- package/src/__snapshots__/TextField.test.tsx.snap +19 -2
- package/src/__snapshots__/TypedSignatureField.test.tsx.snap +3 -0
- package/src/__snapshots__/UnifiedAddressAutoComplete.test.tsx.snap +18 -0
- package/src/__snapshots__/WebAddressAutocomplete.test.tsx.snap +12 -0
- package/src/bunSetup.ts +13 -1
- package/src/fieldElements/FieldError.tsx +1 -0
- package/src/fieldElements/__snapshots__/FieldError.test.tsx.snap +2 -0
- package/src/index.tsx +42 -1
- package/src/isolated/ListDetailLayout.isolated.tsx +634 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +7 -0
- package/src/login/LastUsedBadge.tsx +40 -0
- package/src/login/LoginAccountCard.tsx +205 -0
- package/src/login/LoginAccountList.tsx +115 -0
- package/src/login/LoginScreen.test.tsx +837 -1
- package/src/login/LoginScreen.tsx +674 -91
- package/src/login/OutlinePill.tsx +110 -0
- package/src/login/TwoFactorChallengeScreen.test.tsx +376 -0
- package/src/login/TwoFactorChallengeScreen.tsx +307 -0
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +1454 -334
- package/src/login/loginMethods.test.ts +53 -0
- package/src/login/loginMethods.ts +60 -0
- package/src/login/loginTypes.ts +208 -5
- package/src/pdfHtmlTemplate.test.ts +243 -4
- package/src/pdfHtmlTemplate.ts +93 -0
- package/src/security/AccountSecurityScreen.test.tsx +262 -0
- package/src/security/AccountSecurityScreen.tsx +156 -0
- package/src/security/LinkedAccountsCard.test.tsx +371 -0
- package/src/security/LinkedAccountsCard.tsx +297 -0
- package/src/security/PasskeysCard.test.tsx +378 -0
- package/src/security/PasskeysCard.tsx +371 -0
- package/src/security/PasswordCard.test.tsx +445 -0
- package/src/security/PasswordCard.tsx +342 -0
- package/src/security/SessionsCard.test.tsx +349 -0
- package/src/security/SessionsCard.tsx +362 -0
- package/src/security/TwoFactorSettingsCard.test.tsx +700 -0
- package/src/security/TwoFactorSettingsCard.tsx +872 -0
- package/src/security/securityMethods.test.ts +101 -0
- package/src/security/securityMethods.ts +104 -0
- package/src/security/securityTypes.ts +480 -0
- package/src/security/userAgent.test.ts +119 -0
- package/src/security/userAgent.ts +102 -0
- package/src/signUp/OAuthButtons.test.tsx +27 -0
- package/src/signUp/OAuthButtons.tsx +153 -19
- package/src/signUp/SignUpScreen.test.tsx +170 -1
- package/src/signUp/SignUpScreen.tsx +87 -25
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -11
- package/src/signUp/signUpTypes.ts +23 -1
- package/src/useConsentForms.test.ts +37 -1
- package/src/useConsentForms.ts +25 -0
- package/src/useProvisionalConsent.test.ts +256 -0
- package/src/useProvisionalConsent.ts +218 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { Pressable, View } from "react-native";
|
|
4
|
+
import { Box } from "../Box";
|
|
5
|
+
import { Button } from "../Button";
|
|
6
|
+
import { Heading } from "../Heading";
|
|
7
|
+
import { Icon } from "../Icon";
|
|
8
|
+
import { LabeledCheckBox } from "../LabeledCheckBox";
|
|
9
|
+
import { OtpField } from "../OtpField";
|
|
10
|
+
import { Page } from "../Page";
|
|
11
|
+
import { Text } from "../Text";
|
|
12
|
+
import { TextField } from "../TextField";
|
|
13
|
+
import { useTheme } from "../Theme";
|
|
14
|
+
import { maskEmail } from "./loginMethods";
|
|
15
|
+
const DEFAULT_CODE_LENGTH = 6;
|
|
16
|
+
/**
|
|
17
|
+
* The second step of a two-factor sign-in: a one-time code from an authenticator app, or a backup
|
|
18
|
+
* code, with an optional "trust this device" choice. Presentational: it reports the code through
|
|
19
|
+
* `onSubmit` and never calls an auth client itself.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <TwoFactorChallengeScreen
|
|
24
|
+
* error={error}
|
|
25
|
+
* loading={isVerifying}
|
|
26
|
+
* onCancel={() => router.replace("/login")}
|
|
27
|
+
* onSubmit={async ({code, kind, trustDevice}) => {
|
|
28
|
+
* if (kind === "totp") {
|
|
29
|
+
* await authClient.twoFactor.verifyTotp({code, trustDevice});
|
|
30
|
+
* } else {
|
|
31
|
+
* await authClient.twoFactor.verifyBackupCode({code, trustDevice});
|
|
32
|
+
* }
|
|
33
|
+
* }}
|
|
34
|
+
* trustDeviceDays={30}
|
|
35
|
+
* />
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const TwoFactorChallengeScreen = ({ onSubmit, loading = false, error, trustDeviceDays, onCancel, cancelText = "Sign in a different way", title, accountLabel, logo, codeLength = DEFAULT_CODE_LENGTH, initialKind = "totp", initialTrustDevice, autoFocus = true, testID = "two-factor-challenge", }) => {
|
|
39
|
+
const [kind, setKind] = useState(initialKind);
|
|
40
|
+
const [totpCode, setTotpCode] = useState("");
|
|
41
|
+
const [backupCode, setBackupCode] = useState("");
|
|
42
|
+
// Trust starts checked for an authenticator code unless the caller opts out. Backup codes
|
|
43
|
+
// keep the same choice when the user switches mode.
|
|
44
|
+
const [trustDevice, setTrustDevice] = useState(initialTrustDevice ?? initialKind === "totp");
|
|
45
|
+
// Remounting the code cells after an error clears them and puts focus back on the first cell.
|
|
46
|
+
const [otpResetKey, setOtpResetKey] = useState(0);
|
|
47
|
+
// Counts finished submissions so the effect below can react after the parent's error lands.
|
|
48
|
+
const [settledCount, setSettledCount] = useState(0);
|
|
49
|
+
const isSubmittingRef = useRef(false);
|
|
50
|
+
const previousRef = useRef({ error, loading, settledCount });
|
|
51
|
+
const canTrustDevice = trustDeviceDays !== undefined && trustDeviceDays > 0;
|
|
52
|
+
const isTotp = kind === "totp";
|
|
53
|
+
const code = isTotp ? totpCode : backupCode.trim();
|
|
54
|
+
const isCodeComplete = isTotp ? totpCode.length === codeLength : code.length > 0;
|
|
55
|
+
const resetCode = useCallback(() => {
|
|
56
|
+
setTotpCode("");
|
|
57
|
+
setBackupCode("");
|
|
58
|
+
setOtpResetKey((current) => current + 1);
|
|
59
|
+
}, []);
|
|
60
|
+
// A rejected code shows as an error: clear the code when a new error arrives, and also when a
|
|
61
|
+
// submission finishes (loading ends or onSubmit settles) with an error set, so the same error
|
|
62
|
+
// text twice still clears it.
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
const previous = previousRef.current;
|
|
65
|
+
previousRef.current = { error, loading, settledCount };
|
|
66
|
+
if (!error) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const isNewError = error !== previous.error;
|
|
70
|
+
const didFinishLoading = previous.loading && !loading;
|
|
71
|
+
const didSettle = settledCount !== previous.settledCount;
|
|
72
|
+
if (isNewError || didFinishLoading || didSettle) {
|
|
73
|
+
resetCode();
|
|
74
|
+
}
|
|
75
|
+
}, [error, loading, resetCode, settledCount]);
|
|
76
|
+
const submit = useCallback(async (submittedCode, submittedKind) => {
|
|
77
|
+
// The ref blocks a second submission (auto-submit plus a Verify press) before loading lands.
|
|
78
|
+
if (loading || !submittedCode || isSubmittingRef.current) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
isSubmittingRef.current = true;
|
|
82
|
+
try {
|
|
83
|
+
await onSubmit({
|
|
84
|
+
code: submittedCode,
|
|
85
|
+
kind: submittedKind,
|
|
86
|
+
trustDevice: canTrustDevice && trustDevice,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.warn("TwoFactorChallengeScreen: onSubmit rejected", error);
|
|
91
|
+
resetCode();
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
isSubmittingRef.current = false;
|
|
95
|
+
setSettledCount((current) => current + 1);
|
|
96
|
+
}
|
|
97
|
+
}, [canTrustDevice, loading, onSubmit, resetCode, trustDevice]);
|
|
98
|
+
const handleSubmitPress = useCallback(async () => {
|
|
99
|
+
if (!isCodeComplete) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
await submit(code, kind);
|
|
103
|
+
}, [code, isCodeComplete, kind, submit]);
|
|
104
|
+
const handleOtpEnter = useCallback((enteredCode) => {
|
|
105
|
+
if (enteredCode.length !== codeLength) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
void submit(enteredCode, "totp");
|
|
109
|
+
}, [codeLength, submit]);
|
|
110
|
+
const handleOtpComplete = useCallback((completedCode) => {
|
|
111
|
+
void submit(completedCode, "totp");
|
|
112
|
+
}, [submit]);
|
|
113
|
+
const handleToggleKind = useCallback(() => {
|
|
114
|
+
setKind((current) => (current === "totp" ? "backup" : "totp"));
|
|
115
|
+
setTotpCode("");
|
|
116
|
+
setBackupCode("");
|
|
117
|
+
}, []);
|
|
118
|
+
const { theme } = useTheme();
|
|
119
|
+
const trustDeviceLabel = "Trust this device";
|
|
120
|
+
const resolvedTitle = title ?? (isTotp ? "Enter your code" : "Use a backup code");
|
|
121
|
+
const namedAccount = accountLabel?.includes("@") ? maskEmail(accountLabel) : accountLabel;
|
|
122
|
+
const totpDescription = namedAccount
|
|
123
|
+
? `Open your authenticator app and enter the ${codeLength}-digit code for ${namedAccount}.`
|
|
124
|
+
: `Open your authenticator app and enter the ${codeLength}-digit code.`;
|
|
125
|
+
const displayedError = error || undefined;
|
|
126
|
+
return (_jsx(Page, { navigation: undefined, children: _jsxs(Box, { alignSelf: "center", flex: "grow", maxWidth: 400, padding: 4, testID: testID, width: "100%", children: [_jsxs(Box, { flex: "grow", gap: 5, width: "100%", children: [Boolean(onCancel) && (_jsx(Pressable, { accessibilityRole: "link", disabled: loading, onPress: onCancel, testID: `${testID}-back`, children: _jsxs(Box, { alignItems: "center", direction: "row", gap: 1, children: [_jsx(Icon, { color: "link", iconName: "chevron-left", size: "md" }), _jsx(Text, { bold: true, color: "link", children: "Back" })] }) })), Boolean(logo) && _jsx(Box, { children: logo }), Boolean(theme) && (_jsx(View, { style: {
|
|
127
|
+
alignItems: "center",
|
|
128
|
+
backgroundColor: theme.surface.secondaryExtraLight,
|
|
129
|
+
borderRadius: theme.radius.full,
|
|
130
|
+
height: 56,
|
|
131
|
+
justifyContent: "center",
|
|
132
|
+
width: 56,
|
|
133
|
+
}, children: _jsx(Icon, { color: "secondaryDark", iconName: isTotp ? "shield-halved" : "lock", size: "xl" }) })), _jsxs(Box, { gap: 2, children: [_jsx(Heading, { size: "xl", testID: `${testID}-title`, children: resolvedTitle }), _jsx(Text, { color: "secondaryLight", testID: `${testID}-description`, children: isTotp
|
|
134
|
+
? totpDescription
|
|
135
|
+
: "Enter one of the backup codes you saved when you turned on two-factor sign-in. Each code works once." })] }), isTotp ? (_jsx(OtpField, { accessibilityLabel: "Authentication code",
|
|
136
|
+
// After a rejected code the cells remount (otpResetKey) and take focus back.
|
|
137
|
+
autoFocus: autoFocus || otpResetKey > 0, disabled: loading, invalid: Boolean(displayedError), length: codeLength, onChange: setTotpCode, onComplete: handleOtpComplete, onEnter: handleOtpEnter, testID: `${testID}-otp`, value: totpCode }, otpResetKey)) : (_jsx(View, { role: displayedError ? "alert" : undefined, testID: displayedError ? `${testID}-error` : undefined, children: _jsx(TextField, { accessibilityLabel: "Backup code", autoComplete: "off", disabled: loading, errorPosition: "below", errorText: displayedError, helperText: "Dashes and spaces are optional.", mono: true, onChange: setBackupCode, onEnter: handleSubmitPress, placeholder: "xxxxx-xxxxx", returnKeyType: "go", testID: `${testID}-backup-input`, title: "Backup code", type: "search", value: backupCode }) })), canTrustDevice && (_jsx(LabeledCheckBox, { checked: trustDevice, disabled: loading, helperText: `We won't ask for a code here for ${trustDeviceDays} days.`, label: trustDeviceLabel, onChange: setTrustDevice, testID: `${testID}-trust-device` })), Boolean(displayedError) && isTotp && (_jsx(View, { role: "alert", style: { width: "100%" }, testID: `${testID}-error`, children: _jsxs(Box, { alignItems: "start", direction: "row", gap: 2, width: "100%", children: [_jsx(Icon, { color: "error", iconName: "circle-exclamation", size: "sm" }), _jsx(View, { style: { flex: 1, minWidth: 0 }, children: _jsx(Text, { color: "error", children: displayedError }) })] }) })), _jsx(Button, { disabled: loading || !isCodeComplete, fullWidth: true, loading: loading, onClick: handleSubmitPress, testID: `${testID}-submit`, text: "Verify" }), _jsx(Box, { alignItems: "center", children: _jsx(Pressable, { accessibilityRole: "link", disabled: loading, onPress: handleToggleKind, testID: `${testID}-backup-toggle`, children: _jsx(Text, { bold: true, color: "link", children: isTotp ? "Use a backup code instead" : "Use your authenticator app" }) }) })] }), Boolean(onCancel) && (_jsx(Box, { alignItems: "center", paddingY: 2, children: _jsx(Pressable, { accessibilityRole: "link", disabled: loading, onPress: onCancel, testID: `${testID}-cancel`, children: _jsx(Text, { color: "secondaryLight", children: cancelText }) }) }))] }) }));
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=TwoFactorChallengeScreen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TwoFactorChallengeScreen.js","sourceRoot":"","sources":["../../src/login/TwoFactorChallengeScreen.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAC,SAAS,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAC,GAAG,EAAC,MAAM,QAAQ,CAAC;AAC3B,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AACjC,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAC;AACrC,OAAO,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,QAAQ,EAAC,MAAM,UAAU,CAAC;AAClC,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAGzC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAsC,CAAC,EAC1E,QAAQ,EACR,OAAO,GAAG,K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@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { GenericOAuthProviderConfig } from "../signUp/signUpTypes";
|
|
2
|
+
/** Ways to name a sign-in method in the login screen's copy. */
|
|
3
|
+
export interface LoginMethodLabels {
|
|
4
|
+
/** Noun form, e.g. "GitHub", "email", "passkey": "Forget this {name} account". */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Form used after "with", e.g. "GitHub", "email", "a passkey": "Continue with {phrase}". */
|
|
7
|
+
phrase: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Names a sign-in method: a branded provider's name, a generic provider's label, "email",
|
|
11
|
+
* "passkey", or the raw id as a last resort.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getLoginMethodLabels: ({ method, genericProviders, }: {
|
|
14
|
+
method: string;
|
|
15
|
+
genericProviders?: GenericOAuthProviderConfig[];
|
|
16
|
+
}) => LoginMethodLabels;
|
|
17
|
+
/**
|
|
18
|
+
* Masks an email for display: `josh@nang.io` becomes `j***@n***.io`. Returns the input when it
|
|
19
|
+
* is not an email.
|
|
20
|
+
*/
|
|
21
|
+
export declare const maskEmail: (email: string) => string;
|
|
22
|
+
/** Appends the last-used marker to an accessible name, e.g. "Continue with GitHub, last used". */
|
|
23
|
+
export declare const withLastUsedLabel: ({ label, lastUsedLabel, }: {
|
|
24
|
+
label: string;
|
|
25
|
+
lastUsedLabel: string;
|
|
26
|
+
}) => string;
|
|
27
|
+
//# sourceMappingURL=loginMethods.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loginMethods.d.ts","sourceRoot":"","sources":["../../src/login/loginMethods.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,0BAA0B,EAAC,MAAM,uBAAuB,CAAC;AAEtE,gEAAgE;AAChE,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,IAAI,EAAE,MAAM,CAAC;IACb,6FAA6F;IAC7F,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,+BAGlC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,0BAA0B,EAAE,CAAC;CACjD,KAAG,iBAUH,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,MAWzC,CAAC;AAEF,kGAAkG;AAClG,eAAO,MAAM,iBAAiB,GAAI,2BAG/B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;CACvB,KAAG,MAEH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getSocialProviderName } from "../SocialLoginButton";
|
|
2
|
+
/**
|
|
3
|
+
* Names a sign-in method: a branded provider's name, a generic provider's label, "email",
|
|
4
|
+
* "passkey", or the raw id as a last resort.
|
|
5
|
+
*/
|
|
6
|
+
export const getLoginMethodLabels = ({ method, genericProviders = [], }) => {
|
|
7
|
+
if (method === "email") {
|
|
8
|
+
return { name: "email", phrase: "email" };
|
|
9
|
+
}
|
|
10
|
+
if (method === "passkey") {
|
|
11
|
+
return { name: "passkey", phrase: "a passkey" };
|
|
12
|
+
}
|
|
13
|
+
const generic = genericProviders.find((provider) => provider.id === method);
|
|
14
|
+
const name = generic?.label ?? getSocialProviderName(method) ?? method;
|
|
15
|
+
return { name, phrase: name };
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Masks an email for display: `josh@nang.io` becomes `j***@n***.io`. Returns the input when it
|
|
19
|
+
* is not an email.
|
|
20
|
+
*/
|
|
21
|
+
export const maskEmail = (email) => {
|
|
22
|
+
const at = email.indexOf("@");
|
|
23
|
+
if (at <= 0 || at === email.length - 1) {
|
|
24
|
+
return email;
|
|
25
|
+
}
|
|
26
|
+
const local = email.slice(0, at);
|
|
27
|
+
const domain = email.slice(at + 1);
|
|
28
|
+
const dot = domain.lastIndexOf(".");
|
|
29
|
+
const host = dot === -1 ? domain : domain.slice(0, dot);
|
|
30
|
+
const tld = dot === -1 ? "" : domain.slice(dot);
|
|
31
|
+
return `${local.charAt(0)}***@${host.charAt(0)}***${tld}`;
|
|
32
|
+
};
|
|
33
|
+
/** Appends the last-used marker to an accessible name, e.g. "Continue with GitHub, last used". */
|
|
34
|
+
export const withLastUsedLabel = ({ label, lastUsedLabel, }) => {
|
|
35
|
+
return `${label}, ${lastUsedLabel.toLocaleLowerCase()}`;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=loginMethods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loginMethods.js","sourceRoot":"","sources":["../../src/login/loginMethods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAC,MAAM,sBAAsB,CAAC;AAW3D;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,EACnC,MAAM,EACN,gBAAgB,GAAG,EAAE,GAItB,EAAqB,EAAE;IACtB,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QACvB,OAAO,EAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAC,CAAC;IAC1C,CAAC;IACD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAC,CAAC;IAChD,CAAC;IACD,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;IAC5E,MAAM,IAAI,GAAG,OAAO,EAAE,KAAK,IAAI,qBAAqB,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC;IACvE,OAAO,EAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAC,CAAC;AAC9B,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAU,EAAE;IACjD,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACnC,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACxD,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChD,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC;AAC5D,CAAC,CAAC;AAEF,kGAAkG;AAClG,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,KAAK,EACL,aAAa,GAId,EAAU,EAAE;IACX,OAAO,GAAG,KAAK,KAAK,aAAa,CAAC,iBAAiB,EAAE,EAAE,CAAC;AAC1D,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type { OAuthProviderConfig } from "../signUp/signUpTypes";
|
|
2
|
+
import type { GenericOAuthProviderConfig, OAuthProviderConfig } from "../signUp/signUpTypes";
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for a login form field.
|
|
5
5
|
*/
|
|
@@ -15,7 +15,47 @@ export interface LoginFieldConfig {
|
|
|
15
15
|
/** Whether the field is required. */
|
|
16
16
|
required?: boolean;
|
|
17
17
|
/** Auto-complete hint for the field. */
|
|
18
|
-
autoComplete?: "current-password" | "on" | "off" | "username";
|
|
18
|
+
autoComplete?: "current-password" | "email" | "new-password" | "on" | "off" | "username";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* An account the login screen can offer as a one-tap "Continue" card: a session already signed
|
|
22
|
+
* in on this device, or an account remembered from an earlier sign-in. Identity fields are
|
|
23
|
+
* optional because apps remember only the method by default.
|
|
24
|
+
*/
|
|
25
|
+
export interface LoginAccountOption {
|
|
26
|
+
/** Stable id: the session token or user id for a session, the remembered entry id otherwise. */
|
|
27
|
+
id: string;
|
|
28
|
+
/** Display name, when known. */
|
|
29
|
+
name?: string;
|
|
30
|
+
/** Email address, when known. */
|
|
31
|
+
email?: string;
|
|
32
|
+
/** Avatar image URL, when known. */
|
|
33
|
+
image?: string;
|
|
34
|
+
/** How the account signs in: a provider id, `"email"`, or `"passkey"`. */
|
|
35
|
+
method: string;
|
|
36
|
+
}
|
|
37
|
+
/** Where a "Continue" card came from: a signed-in device session or a remembered account. */
|
|
38
|
+
export type LoginAccountSource = "session" | "remembered";
|
|
39
|
+
/**
|
|
40
|
+
* A message shown under the heading, such as guidance after an `account_not_linked` error.
|
|
41
|
+
* Info notices can be dismissed. A wrong password is not a notice: it is `passwordError`.
|
|
42
|
+
*/
|
|
43
|
+
export interface LoginNotice {
|
|
44
|
+
/** Visual tone of the notice. */
|
|
45
|
+
tone: "info" | "warning" | "error";
|
|
46
|
+
/** Optional bold line above `text`. */
|
|
47
|
+
title?: string;
|
|
48
|
+
/** Message text. */
|
|
49
|
+
text: string;
|
|
50
|
+
/** Label for an optional action button under the text. */
|
|
51
|
+
actionLabel?: string;
|
|
52
|
+
/** Callback for the action button. */
|
|
53
|
+
onAction?: () => void | Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Sign-in method the action should bring forward: `"email"` focuses the email field, any other
|
|
56
|
+
* id expands the method list. The screen does this before calling `onAction`.
|
|
57
|
+
*/
|
|
58
|
+
focusMethod?: string;
|
|
19
59
|
}
|
|
20
60
|
/**
|
|
21
61
|
* Props for the LoginScreen component.
|
|
@@ -29,13 +69,28 @@ export interface LoginScreenProps {
|
|
|
29
69
|
oauthProviders?: OAuthProviderConfig[];
|
|
30
70
|
/** Custom logo or banner to display above the form. */
|
|
31
71
|
logo?: ReactNode;
|
|
32
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Title text for the login form. Defaults to "Welcome back" when accounts are offered and
|
|
74
|
+
* "Sign in" otherwise.
|
|
75
|
+
*/
|
|
33
76
|
title?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Line under the title. Defaults to "Pick up where you left off." when accounts are offered and
|
|
79
|
+
* "Choose how you want to sign in." otherwise.
|
|
80
|
+
*/
|
|
81
|
+
subtitle?: string;
|
|
34
82
|
/** Whether the form is in a loading state. */
|
|
35
83
|
loading?: boolean;
|
|
36
|
-
/** Error message
|
|
84
|
+
/** Error message shown in a banner under the heading. A `notice` wins when both are set. */
|
|
37
85
|
error?: string;
|
|
38
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Wrong-password message shown under the password field, not in the banner.
|
|
88
|
+
*/
|
|
89
|
+
passwordError?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Text of the "Create an account" link in the footer.
|
|
92
|
+
* @default "Create an account"
|
|
93
|
+
*/
|
|
39
94
|
signUpLinkText?: string;
|
|
40
95
|
/** Callback triggered when the sign-up link is pressed. */
|
|
41
96
|
onSignUpPress?: () => void;
|
|
@@ -45,7 +100,149 @@ export interface LoginScreenProps {
|
|
|
45
100
|
onForgotPasswordPress?: () => void;
|
|
46
101
|
/** Alias for `onForgotPasswordPress`. */
|
|
47
102
|
onForgotPassword?: () => void;
|
|
103
|
+
/**
|
|
104
|
+
* Sign-in providers without a branded button (for example a generic OIDC provider). They
|
|
105
|
+
* render after `oauthProviders` with the testID `${testID}-oauth-${id}`.
|
|
106
|
+
*/
|
|
107
|
+
genericProviders?: GenericOAuthProviderConfig[];
|
|
108
|
+
/**
|
|
109
|
+
* The method this device signed in with last: a provider id (`"google"`, `"github"`,
|
|
110
|
+
* `"mock-oidc"`, ...), `"email"`, or `"passkey"`. That method gets a "Last used" pill
|
|
111
|
+
* (testID `${testID}-last-used-${method}`). A provider moves to the front of the provider
|
|
112
|
+
* list, and a passkey leads the method stack. Methods stay above the email form. A method the
|
|
113
|
+
* screen does not offer is ignored.
|
|
114
|
+
*/
|
|
115
|
+
lastUsedMethod?: string;
|
|
116
|
+
/** Text of the last-used badge. Defaults to "Last used". */
|
|
117
|
+
lastUsedLabel?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Sessions already signed in on this device. Each renders a "Continue" card that switches to
|
|
120
|
+
* it in one tap. Requires `onContinue`.
|
|
121
|
+
*/
|
|
122
|
+
currentSessions?: LoginAccountOption[];
|
|
123
|
+
/**
|
|
124
|
+
* Accounts remembered on this device. Each renders a row in the continue-as list that
|
|
125
|
+
* re-authenticates with the remembered method. `onForget` reveals Remove in the list's Edit
|
|
126
|
+
* mode. Requires `onContinue`.
|
|
127
|
+
*/
|
|
128
|
+
rememberedAccounts?: LoginAccountOption[];
|
|
129
|
+
/**
|
|
130
|
+
* Called when a "Continue" card is pressed. Cards are numbered sessions first, then remembered
|
|
131
|
+
* accounts (testID `${testID}-continue-${index}`).
|
|
132
|
+
*/
|
|
133
|
+
onContinue?: (account: LoginAccountOption, source: LoginAccountSource) => void | Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Called when a remembered account's Remove button is pressed in Edit mode
|
|
136
|
+
* (testID `${testID}-forget-${index}`). Sessions are never forgettable here.
|
|
137
|
+
*/
|
|
138
|
+
onForget?: (account: LoginAccountOption) => void | Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Replaces the screen body with the password step for this email account. Set by the controller
|
|
141
|
+
* when a continue-as row has a usable email. Requires `onCancelContinue` to return.
|
|
142
|
+
*/
|
|
143
|
+
continuingAccount?: LoginAccountOption;
|
|
144
|
+
/** Leaves the password step and returns to the account list. */
|
|
145
|
+
onCancelContinue?: () => void;
|
|
146
|
+
/**
|
|
147
|
+
* Opens the screen with the other sign-in methods expanded. Returning users start collapsed
|
|
148
|
+
* behind "Sign in another way".
|
|
149
|
+
*/
|
|
150
|
+
initialMethodsExpanded?: boolean;
|
|
151
|
+
/** Opens the account list in Edit mode, where remembered accounts can be removed. */
|
|
152
|
+
initialAccountsEditing?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Shows a "Sign in with a passkey" button (testID `${testID}-passkey-button`) that calls this.
|
|
155
|
+
*/
|
|
156
|
+
onPasskeyPress?: () => void | Promise<void>;
|
|
157
|
+
/** Text of the passkey button. Defaults to "Sign in with a passkey". */
|
|
158
|
+
passkeyButtonText?: string;
|
|
159
|
+
/**
|
|
160
|
+
* On web, sets the email field's `autocomplete` to `"username webauthn"` so the browser offers
|
|
161
|
+
* saved passkeys in the field's autofill (conditional mediation). Ignored on native.
|
|
162
|
+
*/
|
|
163
|
+
passkeyAutofill?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Values the form starts with, keyed by field name, such as `{email: "jane@example.com"}`.
|
|
166
|
+
* When a new object is passed later, its fields replace what is in the form and the other
|
|
167
|
+
* fields keep what the user typed, so a "Continue" card can prefill the email.
|
|
168
|
+
*/
|
|
169
|
+
initialValues?: Record<string, string>;
|
|
170
|
+
/** A message under the heading (testID `${testID}-notice`). */
|
|
171
|
+
notice?: LoginNotice;
|
|
48
172
|
/** Test ID for the root element. */
|
|
49
173
|
testID?: string;
|
|
50
174
|
}
|
|
175
|
+
/** Which kind of second factor a two-factor challenge submits. */
|
|
176
|
+
export type TwoFactorCodeKind = "totp" | "backup";
|
|
177
|
+
/** What {@link TwoFactorChallengeScreenProps.onSubmit} receives. */
|
|
178
|
+
export interface TwoFactorChallengeSubmission {
|
|
179
|
+
/** The code as entered: six digits for `totp`, a trimmed backup code for `backup`. */
|
|
180
|
+
code: string;
|
|
181
|
+
/** `totp` for an authenticator app code, `backup` for a one-time backup code. */
|
|
182
|
+
kind: TwoFactorCodeKind;
|
|
183
|
+
/** True when the user checked "Don't ask again on this device". Always false without `trustDeviceDays`. */
|
|
184
|
+
trustDevice: boolean;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Props for the TwoFactorChallengeScreen component.
|
|
188
|
+
*/
|
|
189
|
+
export interface TwoFactorChallengeScreenProps {
|
|
190
|
+
/** Called with the code, its kind, and the trust-device choice. A TOTP code submits itself once complete. */
|
|
191
|
+
onSubmit: (values: TwoFactorChallengeSubmission) => void | Promise<void>;
|
|
192
|
+
/** Disables the form and shows a spinner on the submit button. */
|
|
193
|
+
loading?: boolean;
|
|
194
|
+
/** Error text, such as an invalid code, shown with `role="alert"`. A new error clears the entered code. */
|
|
195
|
+
error?: string;
|
|
196
|
+
/**
|
|
197
|
+
* Shows a "Don't ask again on this device for N days" checkbox. Leave unset to hide it. Better
|
|
198
|
+
* Auth trusts a device for 30 days by default.
|
|
199
|
+
*/
|
|
200
|
+
trustDeviceDays?: number;
|
|
201
|
+
/** Shows a back link and a footer link (text via `cancelText`), for example back to sign-in. */
|
|
202
|
+
onCancel?: () => void;
|
|
203
|
+
/**
|
|
204
|
+
* Text for the footer link.
|
|
205
|
+
* @default "Sign in a different way"
|
|
206
|
+
*/
|
|
207
|
+
cancelText?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Heading text. Defaults to "Enter your code" for an authenticator code and "Use a backup code"
|
|
210
|
+
* for a backup code.
|
|
211
|
+
*/
|
|
212
|
+
title?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Account the code is for, usually an email. The authenticator subtitle names it. The screen
|
|
215
|
+
* masks an email address.
|
|
216
|
+
*/
|
|
217
|
+
accountLabel?: string;
|
|
218
|
+
/** Optional logo above the heading. */
|
|
219
|
+
logo?: ReactNode;
|
|
220
|
+
/**
|
|
221
|
+
* Digits in an authenticator code.
|
|
222
|
+
* @default 6
|
|
223
|
+
*/
|
|
224
|
+
codeLength?: number;
|
|
225
|
+
/**
|
|
226
|
+
* The mode the screen opens in.
|
|
227
|
+
* @default "totp"
|
|
228
|
+
*/
|
|
229
|
+
initialKind?: TwoFactorCodeKind;
|
|
230
|
+
/**
|
|
231
|
+
* Whether "Trust this device" starts checked. Defaults to checked for an authenticator code
|
|
232
|
+
* and unchecked for a backup code. Set `false` to start unchecked.
|
|
233
|
+
*/
|
|
234
|
+
initialTrustDevice?: boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Focuses the first code cell when the screen mounts. Turn it off when the screen is not the
|
|
237
|
+
* page's main task (a preview or gallery), since focusing scrolls the page to the cells. A
|
|
238
|
+
* rejected code still returns focus to the first cell.
|
|
239
|
+
* @default true
|
|
240
|
+
*/
|
|
241
|
+
autoFocus?: boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Root testID; child testIDs are derived from it.
|
|
244
|
+
* @default "two-factor-challenge"
|
|
245
|
+
*/
|
|
246
|
+
testID?: string;
|
|
247
|
+
}
|
|
51
248
|
//# sourceMappingURL=loginTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loginTypes.d.ts","sourceRoot":"","sources":["../../src/login/loginTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"loginTypes.d.ts","sourceRoot":"","sources":["../../src/login/loginTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAC,0BAA0B,EAAE,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE3F;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uDAAuD;IACvD,IAAI,EAAE,MA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,CAAC;IACtB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -11,6 +11,15 @@ interface PdfUserInfo {
|
|
|
11
11
|
name?: string;
|
|
12
12
|
email?: string;
|
|
13
13
|
}
|
|
14
|
+
/** A signature staff recorded on the user's behalf. Dates are ISO strings. */
|
|
15
|
+
export interface PdfProvisionalSignature {
|
|
16
|
+
signedAt: string;
|
|
17
|
+
signedByName: string;
|
|
18
|
+
/** The signer's note. Pass it only on admin printouts; the user never sees it. */
|
|
19
|
+
note?: string;
|
|
20
|
+
signerIp?: string;
|
|
21
|
+
voidedAt?: string;
|
|
22
|
+
}
|
|
14
23
|
export interface PdfTemplateData {
|
|
15
24
|
title: string;
|
|
16
25
|
formTitle: string;
|
|
@@ -21,11 +30,19 @@ export interface PdfTemplateData {
|
|
|
21
30
|
contentSnapshot?: string;
|
|
22
31
|
responseId?: string;
|
|
23
32
|
userInfo?: PdfUserInfo;
|
|
33
|
+
provisionalSignature?: PdfProvisionalSignature;
|
|
24
34
|
}
|
|
25
35
|
export declare const buildConsentPdfHtml: (data: PdfTemplateData) => string;
|
|
26
36
|
export declare const sharePdfFromHtml: (options: {
|
|
27
37
|
html: string;
|
|
28
38
|
filename: string;
|
|
29
39
|
}) => Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Open the print dialog for consent HTML (for example from `buildConsentPdfHtml`). Native uses
|
|
42
|
+
* `expo-print`; web prints from a hidden iframe so the app page itself is not printed.
|
|
43
|
+
*/
|
|
44
|
+
export declare const printConsentHtml: ({ html }: {
|
|
45
|
+
html: string;
|
|
46
|
+
}) => Promise<void>;
|
|
30
47
|
export {};
|
|
31
48
|
//# sourceMappingURL=pdfHtmlTemplate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdfHtmlTemplate.d.ts","sourceRoot":"","sources":["../src/pdfHtmlTemplate.ts"],"names":[],"mappings":"AAGA,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,WAAW;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,UAAU,WAAW;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,UAAU,CAAC,EAAE,WAAW,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"pdfHtmlTemplate.d.ts","sourceRoot":"","sources":["../src/pdfHtmlTemplate.ts"],"names":[],"mappings":"AAGA,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,WAAW;IACnB,KAAK,EAAE,MAAM,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(field.value)}</td>
|
|
14
14
|
</tr>`;
|
|
15
15
|
};
|
|
16
|
+
/** Format an ISO date for print; anything that is not ISO prints as written. */
|
|
17
|
+
const formatPrintDate = (value) => {
|
|
18
|
+
const date = DateTime.fromISO(value);
|
|
19
|
+
return date.isValid ? date.toLocaleString(DateTime.DATETIME_FULL) : value;
|
|
20
|
+
};
|
|
21
|
+
const renderProvisionalSignature = (signature) => {
|
|
22
|
+
if (!signature) {
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
const rows = [
|
|
26
|
+
renderField({ label: "Signed by:", value: signature.signedByName }),
|
|
27
|
+
signature.signedAt
|
|
28
|
+
? renderField({ label: "Signed at:", value: formatPrintDate(signature.signedAt) })
|
|
29
|
+
: "",
|
|
30
|
+
signature.note ? renderField({ label: "Note:", value: signature.note }) : "",
|
|
31
|
+
signature.signerIp ? renderField({ label: "Signer IP:", value: signature.signerIp }) : "",
|
|
32
|
+
].join("\n");
|
|
33
|
+
const voidedHtml = signature.voidedAt
|
|
34
|
+
? `<div class="voided">Voided ${escapeHtml(formatPrintDate(signature.voidedAt))}</div>`
|
|
35
|
+
: "";
|
|
36
|
+
return `<div class="section">
|
|
37
|
+
<h2>Provisional signature</h2>
|
|
38
|
+
<table>${rows}</table>
|
|
39
|
+
${voidedHtml}
|
|
40
|
+
</div>`;
|
|
41
|
+
};
|
|
16
42
|
export const buildConsentPdfHtml = (data) => {
|
|
17
43
|
const now = DateTime.now().toLocaleString(DateTime.DATETIME_FULL);
|
|
18
44
|
const fieldsHtml = data.fields.map(renderField).join("\n");
|
|
@@ -125,6 +151,11 @@ export const buildConsentPdfHtml = (data) => {
|
|
|
125
151
|
.section {
|
|
126
152
|
margin-bottom: 4mm;
|
|
127
153
|
}
|
|
154
|
+
.voided {
|
|
155
|
+
font-weight: bold;
|
|
156
|
+
color: #a00000;
|
|
157
|
+
margin-top: 2mm;
|
|
158
|
+
}
|
|
128
159
|
@page {
|
|
129
160
|
size: A4;
|
|
130
161
|
margin: 20mm;
|
|
@@ -144,6 +175,7 @@ export const buildConsentPdfHtml = (data) => {
|
|
|
144
175
|
${userInfoHtml}
|
|
145
176
|
${checkboxesHtml}
|
|
146
177
|
${auditTrailHtml}
|
|
178
|
+
${renderProvisionalSignature(data.provisionalSignature)}
|
|
147
179
|
${signatureHtml}
|
|
148
180
|
${contentSnapshotHtml}
|
|
149
181
|
|
|
@@ -167,4 +199,50 @@ export const sharePdfFromHtml = async (options) => {
|
|
|
167
199
|
UTI: "com.adobe.pdf",
|
|
168
200
|
});
|
|
169
201
|
};
|
|
202
|
+
/** The last web print frame, removed before the next print in case `afterprint` never fired. */
|
|
203
|
+
let lastPrintFrame;
|
|
204
|
+
/**
|
|
205
|
+
* Open the print dialog for consent HTML (for example from `buildConsentPdfHtml`). Native uses
|
|
206
|
+
* `expo-print`; web prints from a hidden iframe so the app page itself is not printed.
|
|
207
|
+
*/
|
|
208
|
+
export const printConsentHtml = async ({ html }) => {
|
|
209
|
+
if (Platform.OS !== "web") {
|
|
210
|
+
const Print = await import("expo-print");
|
|
211
|
+
await Print.printAsync({ html });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
// Consent HTML can hold PHI, so never leave an old frame in the page.
|
|
215
|
+
lastPrintFrame?.remove();
|
|
216
|
+
await new Promise((resolve, reject) => {
|
|
217
|
+
const iframe = document.createElement("iframe");
|
|
218
|
+
lastPrintFrame = iframe;
|
|
219
|
+
iframe.setAttribute("aria-hidden", "true");
|
|
220
|
+
iframe.style.position = "fixed";
|
|
221
|
+
iframe.style.width = "0";
|
|
222
|
+
iframe.style.height = "0";
|
|
223
|
+
iframe.style.border = "0";
|
|
224
|
+
iframe.style.visibility = "hidden";
|
|
225
|
+
iframe.onload = () => {
|
|
226
|
+
const frameWindow = iframe.contentWindow;
|
|
227
|
+
if (!frameWindow) {
|
|
228
|
+
iframe.remove();
|
|
229
|
+
reject(new Error("Print frame did not load"));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
// Some browsers return from print() before the dialog closes; remove the frame after.
|
|
233
|
+
frameWindow.addEventListener("afterprint", () => iframe.remove());
|
|
234
|
+
try {
|
|
235
|
+
frameWindow.focus();
|
|
236
|
+
frameWindow.print();
|
|
237
|
+
resolve();
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
iframe.remove();
|
|
241
|
+
reject(error);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
iframe.srcdoc = html;
|
|
245
|
+
document.body.appendChild(iframe);
|
|
246
|
+
});
|
|
247
|
+
};
|
|
170
248
|
//# sourceMappingURL=pdfHtmlTemplate.js.map
|