@terreno/ui 57.19.2 → 57.21.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 +443 -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 +175 -34
- 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 +11 -9
- 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/HeightField.js +8 -8
- package/dist/HeightField.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/PickerSelect.js +9 -9
- package/dist/PickerSelect.js.map +1 -1
- 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/TapToEdit.d.ts +1 -1
- package/dist/TapToEdit.d.ts.map +1 -1
- package/dist/TapToEdit.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +48 -14
- package/dist/TextField.js.map +1 -1
- package/dist/Theme.d.ts.map +1 -1
- package/dist/Theme.js +16 -0
- package/dist/Theme.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 +5 -2
- package/src/Accordion.test.tsx +5 -0
- package/src/Accordion.tsx +3 -8
- package/src/ActionSheet.test.tsx +13 -13
- package/src/AddressField.test.tsx +9 -3
- package/src/AnnouncementNavigator.test.tsx +4 -4
- package/src/AreaChart.test.tsx +15 -0
- package/src/Avatar.test.tsx +8 -0
- package/src/Avatar.tsx +2 -0
- package/src/Badge.test.tsx +1 -1
- package/src/Banner.test.tsx +0 -1
- package/src/BarChart.test.tsx +15 -0
- package/src/Box.test.tsx +143 -75
- package/src/Box.tsx +44 -2
- package/src/Button.test.tsx +11 -6
- package/src/Card.test.tsx +2 -2
- package/src/Card.tsx +2 -2
- package/src/Common.ts +194 -36
- package/src/ConflictSheet.test.tsx +5 -5
- package/src/ConsentFormScreen.test.tsx +87 -1
- package/src/ConsentFormScreen.tsx +28 -4
- package/src/ConsentNavigator.test.tsx +1 -2
- package/src/CustomSelectField.test.tsx +16 -4
- package/src/DataTable.test.tsx +4 -4
- package/src/DataTableVirtualizationRegression.test.tsx +1 -0
- package/src/DateTimeActionSheet.test.tsx +2 -0
- package/src/DateTimeField.test.tsx +3 -12
- package/src/DateTimeField.tsx +11 -9
- package/src/DismissButton.test.tsx +22 -4
- package/src/DonutChart.test.tsx +15 -0
- package/src/EmailField.test.tsx +13 -22
- package/src/EmojiSelector.test.tsx +2 -2
- package/src/ErrorBoundary.test.tsx +5 -3
- package/src/Field.test.tsx +20 -44
- 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 +40 -16
- package/src/GPTChat.tsx +8 -2
- package/src/Heading.test.tsx +15 -1
- package/src/Heading.tsx +6 -1
- package/src/HeightField.tsx +8 -8
- package/src/Icon.test.tsx +54 -3
- package/src/Icon.tsx +92 -3
- package/src/IconButton.test.tsx +85 -0
- package/src/Image.test.tsx +1 -1
- package/src/LabeledCheckBox.test.tsx +45 -0
- package/src/LabeledCheckBox.tsx +89 -0
- package/src/Link.test.tsx +11 -4
- package/src/ListDetailLayout.tsx +247 -0
- package/src/MarkdownEditor.tsx +2 -1
- package/src/MarkdownView.test.tsx +1 -1
- package/src/MediaQuery.ts +1 -0
- package/src/MobileAddressAutoComplete.test.tsx +2 -1
- package/src/Modal.test.tsx +7 -2
- package/src/ModalSheet.test.tsx +5 -4
- package/src/MultiselectField.test.tsx +17 -3
- package/src/NumberField.test.tsx +14 -14
- package/src/NumberPickerActionSheet.test.tsx +1 -1
- package/src/OpenAPIContext.test.tsx +4 -4
- package/src/OpenAPIRenderRegression.test.tsx +1 -1
- package/src/OtpField.test.tsx +280 -0
- package/src/OtpField.tsx +307 -0
- package/src/P0RenderRegression.test.tsx +7 -1
- package/src/P1RenderRegression.test.tsx +1 -0
- package/src/P2ButtonRenderRegression.test.tsx +1 -0
- package/src/Page.test.tsx +1 -1
- package/src/PhoneNumberField.test.tsx +14 -38
- package/src/PickerSelect.tsx +9 -9
- package/src/Popover.test.tsx +2 -2
- package/src/ProvisionalConsentSigner.test.tsx +625 -0
- package/src/ProvisionalConsentSigner.tsx +423 -0
- package/src/RadioField.test.tsx +7 -2
- package/src/ResponsiveBreakpoint.test.tsx +7 -0
- package/src/ResponsiveBreakpoint.tsx +14 -0
- package/src/RootImportRegression.test.tsx +3 -0
- package/src/SegmentedControl.test.tsx +21 -12
- package/src/SidebarNavigation.test.tsx +18 -6
- package/src/Signature.test.tsx +20 -23
- package/src/Slider.test.tsx +1 -1
- package/src/SocialLoginButton.test.tsx +14 -0
- package/src/SocialLoginButton.tsx +51 -7
- package/src/SplitPage.native.tsx +3 -1
- package/src/SplitPage.test.tsx +15 -5
- package/src/SplitPage.tsx +11 -5
- package/src/SyncStatusBanner.test.tsx +61 -4
- package/src/SyncStatusBanner.tsx +29 -3
- package/src/TapToEdit.test.tsx +38 -15
- package/src/TapToEdit.tsx +1 -1
- package/src/TerrenoFontProvider.test.tsx +1 -1
- package/src/Text.test.tsx +4 -4
- package/src/TextField.test.tsx +232 -9
- package/src/TextField.tsx +70 -12
- package/src/Theme.test.tsx +49 -0
- package/src/Theme.tsx +16 -0
- package/src/Toast.test.tsx +5 -5
- package/src/ToastNotifications.test.tsx +73 -70
- package/src/ToastNotifications.webModal.test.tsx +2 -2
- package/src/Tooltip.test.tsx +3 -3
- package/src/UnifiedAddressAutoComplete.test.tsx +1 -1
- package/src/UserInactivity.test.tsx +4 -2
- package/src/WebAddressAutocomplete.test.tsx +12 -12
- package/src/WebDropdownMenu.test.tsx +16 -15
- 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__/Card.test.tsx.snap +1 -1
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +3 -0
- package/src/__snapshots__/DismissButton.test.tsx.snap +3 -3
- package/src/__snapshots__/EmailField.test.tsx.snap +6 -0
- package/src/__snapshots__/Field.test.tsx.snap +41 -2
- package/src/__snapshots__/Heading.test.tsx.snap +1 -1
- package/src/__snapshots__/HeightField.test.tsx.snap +2 -0
- package/src/__snapshots__/Image.test.tsx.snap +1 -1
- package/src/__snapshots__/MobileAddressAutoComplete.test.tsx.snap +3 -0
- package/src/__snapshots__/NumberField.test.tsx.snap +3 -0
- package/src/__snapshots__/Page.test.tsx.snap +2 -2
- 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__/Text.test.tsx.snap +1 -1
- 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/asks/AskCard.test.tsx +16 -13
- package/src/asks/AskFiles.test.tsx +5 -1
- package/src/asks/askFileRefs.test.ts +1 -1
- package/src/asks/askSummary.test.ts +2 -2
- package/src/benchmarks/importTiming.ts +1 -1
- package/src/blocks/BlocksView.test.tsx +20 -11
- package/src/bunSetup.ts +14 -2
- package/src/dataTableFilters.test.tsx +1 -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 +632 -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 +839 -3
- 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 +171 -2
- 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/table/tableContext.test.tsx +5 -5
- package/src/test-utils.tsx +56 -1
- package/src/testing/reactDomServer.d.ts +7 -0
- package/src/useConsentForms.test.ts +38 -2
- package/src/useConsentForms.ts +25 -0
- package/src/useProvisionalConsent.test.ts +256 -0
- package/src/useProvisionalConsent.ts +218 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {DateTime} from "luxon";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
formatRelativeSecurityTime,
|
|
6
|
+
formatSecurityDate,
|
|
7
|
+
getProviderDisplay,
|
|
8
|
+
getRejectionMessage,
|
|
9
|
+
hasPasswordCredential,
|
|
10
|
+
} from "./securityMethods";
|
|
11
|
+
|
|
12
|
+
describe("securityMethods", () => {
|
|
13
|
+
it("hasPasswordCredential finds the credential account", () => {
|
|
14
|
+
expect(
|
|
15
|
+
hasPasswordCredential([
|
|
16
|
+
{id: "acc-google", providerId: "google"},
|
|
17
|
+
{id: "acc-credential", providerId: "credential"},
|
|
18
|
+
])
|
|
19
|
+
).toBe(true);
|
|
20
|
+
expect(hasPasswordCredential([{id: "acc-google", providerId: "google"}])).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("getProviderDisplay prefers the app label and icon, then brand, then a key", () => {
|
|
24
|
+
expect(getProviderDisplay({providerId: "github"})).toEqual({
|
|
25
|
+
iconName: "github",
|
|
26
|
+
iconType: "brand",
|
|
27
|
+
label: "GitHub",
|
|
28
|
+
});
|
|
29
|
+
expect(
|
|
30
|
+
getProviderDisplay({
|
|
31
|
+
provider: {iconName: "building", id: "okta", label: "Okta"},
|
|
32
|
+
providerId: "okta",
|
|
33
|
+
})
|
|
34
|
+
).toEqual({iconName: "building", iconType: "solid", label: "Okta"});
|
|
35
|
+
expect(getProviderDisplay({providerId: "mock-oidc"})).toEqual({
|
|
36
|
+
iconName: "key",
|
|
37
|
+
iconType: "solid",
|
|
38
|
+
label: "mock-oidc",
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("getProviderDisplay names a provider id that matches an Object.prototype key by its id", () => {
|
|
43
|
+
for (const providerId of ["__proto__", "constructor"]) {
|
|
44
|
+
expect(getProviderDisplay({providerId})).toEqual({
|
|
45
|
+
iconName: "key",
|
|
46
|
+
iconType: "solid",
|
|
47
|
+
label: providerId,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("formatSecurityDate formats ISO dates and ignores missing or invalid ones", () => {
|
|
53
|
+
const iso = "2026-03-03T12:00:00.000Z";
|
|
54
|
+
// Expectations come from Luxon so they follow the runner's locale and time zone.
|
|
55
|
+
expect(formatSecurityDate(iso)).toBe(DateTime.fromISO(iso).toLocaleString(DateTime.DATE_MED));
|
|
56
|
+
expect(formatSecurityDate(new Date(iso))).toBe(
|
|
57
|
+
DateTime.fromISO(iso).toLocaleString(DateTime.DATE_MED)
|
|
58
|
+
);
|
|
59
|
+
expect(formatSecurityDate(new Date("nope"))).toBeUndefined();
|
|
60
|
+
expect(formatSecurityDate(undefined)).toBeUndefined();
|
|
61
|
+
expect(formatSecurityDate("nope")).toBeUndefined();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("getRejectionMessage reads Error and {message} rejections, else falls back", () => {
|
|
65
|
+
expect(getRejectionMessage({error: new Error("Bad"), fallback: "x"})).toBe("Bad");
|
|
66
|
+
expect(getRejectionMessage({error: {message: "Better Auth said no"}, fallback: "x"})).toBe(
|
|
67
|
+
"Better Auth said no"
|
|
68
|
+
);
|
|
69
|
+
expect(getRejectionMessage({error: "string", fallback: "Fallback"})).toBe("Fallback");
|
|
70
|
+
expect(getRejectionMessage({error: {message: 3}, fallback: "Fallback"})).toBe("Fallback");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("formatRelativeSecurityTime is relative to the injected now", () => {
|
|
74
|
+
const now = new Date("2026-03-03T12:00:00.000Z");
|
|
75
|
+
const base = DateTime.fromJSDate(now);
|
|
76
|
+
const fiveMinutesAgo = "2026-03-03T11:55:00.000Z";
|
|
77
|
+
expect(formatRelativeSecurityTime({now, value: fiveMinutesAgo})).toBe(
|
|
78
|
+
DateTime.fromISO(fiveMinutesAgo).toRelative({base}) ?? ""
|
|
79
|
+
);
|
|
80
|
+
const twoDaysAgo = new Date("2026-03-01T12:00:00.000Z");
|
|
81
|
+
expect(formatRelativeSecurityTime({now, value: twoDaysAgo})).toBe(
|
|
82
|
+
DateTime.fromJSDate(twoDaysAgo).toRelative({base}) ?? ""
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("formatRelativeSecurityTime says just now within a minute and for future times", () => {
|
|
87
|
+
const now = new Date("2026-03-03T12:00:00.000Z");
|
|
88
|
+
expect(formatRelativeSecurityTime({now, value: "2026-03-03T11:59:30.000Z"})).toBe("just now");
|
|
89
|
+
expect(formatRelativeSecurityTime({now, value: "2026-03-03T12:05:00.000Z"})).toBe("just now");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("formatRelativeSecurityTime returns undefined for a missing or invalid value", () => {
|
|
93
|
+
expect(formatRelativeSecurityTime({value: undefined})).toBeUndefined();
|
|
94
|
+
expect(formatRelativeSecurityTime({value: "not-a-date"})).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("formatRelativeSecurityTime defaults now to the current time", () => {
|
|
98
|
+
const value = DateTime.now().minus({hours: 3});
|
|
99
|
+
expect(formatRelativeSecurityTime({value: value.toJSDate()})).toBe(value.toRelative() ?? "");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {DateTime} from "luxon";
|
|
2
|
+
|
|
3
|
+
import type {IconName} from "../Common";
|
|
4
|
+
import {getSocialProviderName} from "../SocialLoginButton";
|
|
5
|
+
import type {LinkableProvider, LinkedAccount} from "./securityTypes";
|
|
6
|
+
|
|
7
|
+
/** Better Auth's `providerId` for an email and password account. */
|
|
8
|
+
export const CREDENTIAL_PROVIDER_ID = "credential";
|
|
9
|
+
|
|
10
|
+
/** Providers whose FontAwesome brand icon shares their id. */
|
|
11
|
+
const BRAND_ICON_PROVIDERS = new Set(["apple", "github", "google"]);
|
|
12
|
+
|
|
13
|
+
/** How a provider row names and draws a provider. */
|
|
14
|
+
export interface ProviderDisplay {
|
|
15
|
+
/** Display name, e.g. "GitHub". */
|
|
16
|
+
label: string;
|
|
17
|
+
/** FontAwesome icon name. */
|
|
18
|
+
iconName: IconName;
|
|
19
|
+
/** FontAwesome icon style: `brand` for branded providers. */
|
|
20
|
+
iconType: "brand" | "solid";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Whether the user has a password, i.e. a `"credential"` account. */
|
|
24
|
+
export const hasPasswordCredential = (accounts: LinkedAccount[]): boolean => {
|
|
25
|
+
return accounts.some((account) => account.providerId === CREDENTIAL_PROVIDER_ID);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Names and picks an icon for a provider, preferring the app's own label and icon. */
|
|
29
|
+
export const getProviderDisplay = ({
|
|
30
|
+
providerId,
|
|
31
|
+
provider,
|
|
32
|
+
}: {
|
|
33
|
+
providerId: string;
|
|
34
|
+
provider?: LinkableProvider;
|
|
35
|
+
}): ProviderDisplay => {
|
|
36
|
+
const label = provider?.label ?? getSocialProviderName(providerId) ?? providerId;
|
|
37
|
+
if (provider?.iconName) {
|
|
38
|
+
return {iconName: provider.iconName, iconType: "solid", label};
|
|
39
|
+
}
|
|
40
|
+
if (BRAND_ICON_PROVIDERS.has(providerId)) {
|
|
41
|
+
return {iconName: providerId as IconName, iconType: "brand", label};
|
|
42
|
+
}
|
|
43
|
+
return {iconName: "key", iconType: "solid", label};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** Parses a `Date` or ISO string with Luxon, or undefined when missing or invalid. */
|
|
47
|
+
const toSecurityDateTime = (value?: string | Date): DateTime | undefined => {
|
|
48
|
+
if (!value) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const date = value instanceof Date ? DateTime.fromJSDate(value) : DateTime.fromISO(value);
|
|
52
|
+
return date.isValid ? date : undefined;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Formats a `Date` or ISO string as a short local date ("Mar 3, 2026"), or undefined when missing
|
|
57
|
+
* or invalid.
|
|
58
|
+
*/
|
|
59
|
+
export const formatSecurityDate = (value?: string | Date): string | undefined => {
|
|
60
|
+
return toSecurityDateTime(value)?.toLocaleString(DateTime.DATE_MED);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Formats a `Date` or ISO string relative to `now` ("5 minutes ago"), or undefined when missing or
|
|
65
|
+
* invalid. Anything under a minute old, or in the future (clock skew between client and server),
|
|
66
|
+
* reads "just now". Pass `now` to make the output deterministic.
|
|
67
|
+
*/
|
|
68
|
+
export const formatRelativeSecurityTime = ({
|
|
69
|
+
value,
|
|
70
|
+
now,
|
|
71
|
+
}: {
|
|
72
|
+
value?: string | Date;
|
|
73
|
+
now?: Date;
|
|
74
|
+
}): string | undefined => {
|
|
75
|
+
const date = toSecurityDateTime(value);
|
|
76
|
+
if (!date) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
const base = now ? DateTime.fromJSDate(now) : DateTime.now();
|
|
80
|
+
if (base.diff(date, "seconds").seconds < 60) {
|
|
81
|
+
return "just now";
|
|
82
|
+
}
|
|
83
|
+
return date.toRelative({base}) ?? undefined;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** The message of a rejected callback, or a fallback for non-Error rejections. */
|
|
87
|
+
export const getRejectionMessage = ({
|
|
88
|
+
error,
|
|
89
|
+
fallback,
|
|
90
|
+
}: {
|
|
91
|
+
error: unknown;
|
|
92
|
+
fallback: string;
|
|
93
|
+
}): string => {
|
|
94
|
+
if (error instanceof Error && error.message) {
|
|
95
|
+
return error.message;
|
|
96
|
+
}
|
|
97
|
+
if (typeof error === "object" && error !== null && "message" in error) {
|
|
98
|
+
const {message} = error as {message?: unknown};
|
|
99
|
+
if (typeof message === "string" && message) {
|
|
100
|
+
return message;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return fallback;
|
|
104
|
+
};
|
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
import type {ReactNode} from "react";
|
|
2
|
+
|
|
3
|
+
import type {IconName} from "../Common";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A sign-in account linked to the user, built from a Better Auth `listAccounts` entry. A password
|
|
7
|
+
* is an account too, with `providerId` `"credential"`. Better Auth returns no email per account,
|
|
8
|
+
* so `email` comes from elsewhere (the session user, or a per-account info call) when shown.
|
|
9
|
+
*/
|
|
10
|
+
export interface LinkedAccount {
|
|
11
|
+
/**
|
|
12
|
+
* Better Auth's own account row id (`listAccounts()[i].id`). This is what `unlinkAccount`
|
|
13
|
+
* takes as `accountId`; it also keys the card's rows.
|
|
14
|
+
*/
|
|
15
|
+
id: string;
|
|
16
|
+
/** Provider id: `"google"`, `"github"`, `"apple"`, a generic provider id, or `"credential"`. */
|
|
17
|
+
providerId: string;
|
|
18
|
+
/** The account's id at the provider (Better Auth's `accountId`). Display only. */
|
|
19
|
+
accountId?: string;
|
|
20
|
+
/** Email address on the provider account, when known. */
|
|
21
|
+
email?: string;
|
|
22
|
+
/**
|
|
23
|
+
* When the account was linked: Better Auth's `createdAt`, as a `Date` (the Better Auth client
|
|
24
|
+
* parses dates) or an ISO 8601 string.
|
|
25
|
+
*/
|
|
26
|
+
linkedAt?: string | Date;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A provider the app lets users link: a branded provider or a generic OAuth/OIDC provider. */
|
|
30
|
+
export interface LinkableProvider {
|
|
31
|
+
/** Provider id, matching `LinkedAccount.providerId` and the id passed to `linkSocial`. */
|
|
32
|
+
id: string;
|
|
33
|
+
/** Display name. Defaults to the branded name ("Google", "GitHub", "Apple") or the id. */
|
|
34
|
+
label?: string;
|
|
35
|
+
/** FontAwesome icon. Branded providers default to their brand icon; others to a key. */
|
|
36
|
+
iconName?: IconName;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Props for the LinkedAccountsCard component.
|
|
41
|
+
*/
|
|
42
|
+
export interface LinkedAccountsCardProps {
|
|
43
|
+
/**
|
|
44
|
+
* Every account linked to the user, including the `"credential"` password account. The
|
|
45
|
+
* password is not listed as a row (PasswordCard covers it) but counts as a sign-in method.
|
|
46
|
+
*/
|
|
47
|
+
accounts: LinkedAccount[];
|
|
48
|
+
/**
|
|
49
|
+
* Providers the app offers. Each renders a row, linked or not. A linked account whose
|
|
50
|
+
* provider is not in this list still renders as a linked row after them.
|
|
51
|
+
*/
|
|
52
|
+
providers: LinkableProvider[];
|
|
53
|
+
/**
|
|
54
|
+
* Called when Link is pressed. The row shows a spinner until the returned promise settles. A
|
|
55
|
+
* rejection shows its message as the card error.
|
|
56
|
+
*/
|
|
57
|
+
onLink?: (providerId: string) => void | Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Called after the user confirms Unlink, with the row's account. Pass `account.id` to Better
|
|
60
|
+
* Auth's `unlinkAccount({accountId})`, and throw when it resolves an `error` (the client
|
|
61
|
+
* resolves `{data, error}` instead of rejecting). The row shows a spinner until the returned promise
|
|
62
|
+
* settles. A rejection shows its message as the card error.
|
|
63
|
+
*/
|
|
64
|
+
onUnlink?: (providerId: string, account: LinkedAccount) => void | Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Sign-in methods that are not accounts, such as passkeys. They count toward the last-method
|
|
67
|
+
* rule, so a user with a passkey can unlink their only provider. Better Auth itself refuses to
|
|
68
|
+
* unlink a user's last account unless `account.accountLinking.allowUnlinkingAll` is set, so
|
|
69
|
+
* pass 0 unless the server allows unlinking every account.
|
|
70
|
+
* @default 0
|
|
71
|
+
*/
|
|
72
|
+
otherMethodCount?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Allows unlinking the only remaining sign-in method. Leave false unless the app has another
|
|
75
|
+
* way back in (for example, a verified email for password reset).
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
canUnlinkLast?: boolean;
|
|
79
|
+
/** Error text shown with `role="alert"`, for example from a failed link redirect. */
|
|
80
|
+
error?: string;
|
|
81
|
+
/** Disables every row, for example while accounts load. */
|
|
82
|
+
disabled?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Heading text.
|
|
85
|
+
* @default "Linked accounts"
|
|
86
|
+
*/
|
|
87
|
+
title?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Text under the heading.
|
|
90
|
+
* @default "Sign in with any account linked here."
|
|
91
|
+
*/
|
|
92
|
+
description?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Root testID; child testIDs are derived from it.
|
|
95
|
+
* @default "linked-accounts-card"
|
|
96
|
+
*/
|
|
97
|
+
testID?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Whether a PasswordCard submission changes an existing password or sets a first one. */
|
|
101
|
+
export type PasswordCardMode = "change" | "set";
|
|
102
|
+
|
|
103
|
+
/** What {@link PasswordCardProps.onSubmit} receives. */
|
|
104
|
+
export interface PasswordCardSubmission {
|
|
105
|
+
/** `change` when the user has a password, `set` for an OAuth-only user. */
|
|
106
|
+
mode: PasswordCardMode;
|
|
107
|
+
/** The current password. Present only in `change` mode. */
|
|
108
|
+
currentPassword?: string;
|
|
109
|
+
/** The new password, already checked against `minLength` and the confirmation. */
|
|
110
|
+
newPassword: string;
|
|
111
|
+
/** True when the user checked "Sign out of other devices". Always false in `set` mode. */
|
|
112
|
+
revokeOtherSessions: boolean;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Props for the PasswordCard component.
|
|
117
|
+
*/
|
|
118
|
+
export interface PasswordCardProps {
|
|
119
|
+
/**
|
|
120
|
+
* Whether the user has a password (a `"credential"` account). True shows "Change password";
|
|
121
|
+
* false shows "Set a password".
|
|
122
|
+
*/
|
|
123
|
+
hasPassword: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Called with valid values. Resolve to show the success message and clear the form; reject to
|
|
126
|
+
* show the error's message under the form.
|
|
127
|
+
*/
|
|
128
|
+
onSubmit: (values: PasswordCardSubmission) => Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Shows the "Sign out of other devices" checkbox in change mode.
|
|
131
|
+
* @default true
|
|
132
|
+
*/
|
|
133
|
+
showRevokeOtherSessions?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Minimum new-password length. Better Auth's default is 8.
|
|
136
|
+
* @default 8
|
|
137
|
+
*/
|
|
138
|
+
minLength?: number;
|
|
139
|
+
/** Error text shown with `role="alert"`, for example a wrong current password. */
|
|
140
|
+
error?: string;
|
|
141
|
+
/** Disables the form and shows a spinner on the submit button. */
|
|
142
|
+
loading?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* The signed-in user's email or username. On web it goes in a hidden `autocomplete="username"`
|
|
145
|
+
* field so password managers update that account's saved password.
|
|
146
|
+
*/
|
|
147
|
+
username?: string;
|
|
148
|
+
/**
|
|
149
|
+
* Root testID; child testIDs are derived from it.
|
|
150
|
+
* @default "password-card"
|
|
151
|
+
*/
|
|
152
|
+
testID?: string;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A passkey registered to the user. The shape is a subset of `@better-auth/passkey`'s `Passkey`,
|
|
157
|
+
* so `authClient.passkey.listUserPasskeys()` data can be passed as is.
|
|
158
|
+
*/
|
|
159
|
+
export interface AccountPasskey {
|
|
160
|
+
/** Better Auth's passkey id: what `deletePasskey({id})` and `updatePasskey({id, name})` take. */
|
|
161
|
+
id: string;
|
|
162
|
+
/** The user's label for the passkey. Takes precedence over `authenticatorName`. */
|
|
163
|
+
name?: string;
|
|
164
|
+
/**
|
|
165
|
+
* A fallback label for an unnamed passkey, such as the authenticator model a connected screen
|
|
166
|
+
* looks up with `getAuthenticatorName(aaguid)` from `@better-auth/passkey` ("iCloud Keychain").
|
|
167
|
+
* With neither `name` nor this, the row shows "Unnamed passkey".
|
|
168
|
+
*/
|
|
169
|
+
authenticatorName?: string;
|
|
170
|
+
/** When the passkey was added, as a `Date` (the Better Auth client parses dates) or ISO string. */
|
|
171
|
+
createdAt?: string | Date;
|
|
172
|
+
/**
|
|
173
|
+
* When the passkey was last used to sign in. Better Auth does not store this; pass it when the
|
|
174
|
+
* app tracks it.
|
|
175
|
+
*/
|
|
176
|
+
lastUsedAt?: string | Date;
|
|
177
|
+
/** Whether the credential is backed up (synced) by its provider, such as iCloud Keychain. */
|
|
178
|
+
backedUp?: boolean;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Props for the PasskeysCard component.
|
|
183
|
+
*/
|
|
184
|
+
export interface PasskeysCardProps {
|
|
185
|
+
/** The user's passkeys, one row each, keyed by `id`. */
|
|
186
|
+
passkeys: AccountPasskey[];
|
|
187
|
+
/**
|
|
188
|
+
* Called when the user confirms the Add dialog, with the name they typed (trimmed), or
|
|
189
|
+
* undefined when they left it blank. Pass it to `authClient.passkey.addPasskey({name})`. The
|
|
190
|
+
* Add button shows a spinner until the returned promise settles. A rejection (for example, the
|
|
191
|
+
* user cancelling the browser prompt) shows its message as the card error. The Better Auth
|
|
192
|
+
* client resolves `{data, error}` instead of rejecting, so throw when `error` is set; the same
|
|
193
|
+
* applies to every callback below.
|
|
194
|
+
*/
|
|
195
|
+
onAdd?: (name?: string) => void | Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Called when the user saves a new name in the Rename dialog, with the trimmed name. Pass it to
|
|
198
|
+
* `authClient.passkey.updatePasskey({id, name})`. Same spinner and error handling as `onAdd`.
|
|
199
|
+
*/
|
|
200
|
+
onRename?: (id: string, name: string) => void | Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Called after the user confirms Remove, with the row's passkey. Pass `passkey.id` to
|
|
203
|
+
* `authClient.passkey.deletePasskey({id})`. Same spinner and error handling as `onAdd`.
|
|
204
|
+
*/
|
|
205
|
+
onRemove?: (passkey: AccountPasskey) => void | Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* Whether this device and browser can create passkeys (for example, WebAuthn is available).
|
|
208
|
+
* False hides Add and explains why; existing passkeys can still be renamed and removed.
|
|
209
|
+
* @default true
|
|
210
|
+
*/
|
|
211
|
+
supported?: boolean;
|
|
212
|
+
/** Error text shown with `role="alert"`; overrides a rejection message. */
|
|
213
|
+
error?: string;
|
|
214
|
+
/** Disables every button, for example while passkeys load. */
|
|
215
|
+
disabled?: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Heading text.
|
|
218
|
+
* @default "Passkeys"
|
|
219
|
+
*/
|
|
220
|
+
title?: string;
|
|
221
|
+
/**
|
|
222
|
+
* Text under the heading.
|
|
223
|
+
* @default "Sign in with your fingerprint, face, or screen lock instead of a password."
|
|
224
|
+
*/
|
|
225
|
+
description?: string;
|
|
226
|
+
/**
|
|
227
|
+
* Root testID; child testIDs are derived from it.
|
|
228
|
+
* @default "passkeys-card"
|
|
229
|
+
*/
|
|
230
|
+
testID?: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* A signed-in session. The shape is a subset of Better Auth's session, so `listSessions()` data
|
|
235
|
+
* can be passed as is.
|
|
236
|
+
*/
|
|
237
|
+
export interface AccountSession {
|
|
238
|
+
/** Better Auth's session id. Keys the row. */
|
|
239
|
+
id: string;
|
|
240
|
+
/** The session token: what `revokeSession({token})` takes. */
|
|
241
|
+
token?: string;
|
|
242
|
+
/** The user agent that created the session. The row shows the browser and OS parsed from it. */
|
|
243
|
+
userAgent?: string | null;
|
|
244
|
+
/** The IP address that created the session. */
|
|
245
|
+
ipAddress?: string | null;
|
|
246
|
+
/** A place name for the session ("Denver, US"), when the app looks one up. */
|
|
247
|
+
location?: string;
|
|
248
|
+
/** When the session signed in, as a `Date` or ISO string: the row's "Signed in" time. */
|
|
249
|
+
createdAt?: string | Date;
|
|
250
|
+
/**
|
|
251
|
+
* When the session was last refreshed: the row's "Last refreshed" time. Better Auth moves it
|
|
252
|
+
* only once per `session.updateAge` (a day by default), so it is not a live activity time.
|
|
253
|
+
*/
|
|
254
|
+
updatedAt?: string | Date;
|
|
255
|
+
/** When the session expires. */
|
|
256
|
+
expiresAt?: string | Date;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Props for the SessionsCard component.
|
|
261
|
+
*/
|
|
262
|
+
export interface SessionsCardProps {
|
|
263
|
+
/** The user's active sessions, one row each, keyed by `id`. The current session is listed first. */
|
|
264
|
+
sessions: AccountSession[];
|
|
265
|
+
/**
|
|
266
|
+
* The current session's id (`useSession().data.session.id`). The matching row is marked "This
|
|
267
|
+
* device" and cannot be revoked on its own. Pass this or `currentSessionToken`.
|
|
268
|
+
*/
|
|
269
|
+
currentSessionId?: string;
|
|
270
|
+
/** The current session's token, matched against each session's `token`. */
|
|
271
|
+
currentSessionToken?: string;
|
|
272
|
+
/**
|
|
273
|
+
* Called when the user signs out another session, with that session. Pass `session.token` to
|
|
274
|
+
* `authClient.revokeSession({token})` and throw when it resolves an `error` (the Better Auth
|
|
275
|
+
* client resolves `{data, error}` instead of rejecting). Not offered for the current session. The row shows a
|
|
276
|
+
* spinner until the returned promise settles; a rejection shows its message as the card error.
|
|
277
|
+
*/
|
|
278
|
+
onRevoke?: (session: AccountSession) => void | Promise<void>;
|
|
279
|
+
/**
|
|
280
|
+
* Called after the user confirms "Sign out everywhere else". Call
|
|
281
|
+
* `authClient.revokeOtherSessions()` and throw when it resolves an `error`. Disabled when there
|
|
282
|
+
* are no other sessions.
|
|
283
|
+
*/
|
|
284
|
+
onRevokeOthers?: () => void | Promise<void>;
|
|
285
|
+
/**
|
|
286
|
+
* The time relative times ("Signed in 5 minutes ago") are measured from. When omitted, the card
|
|
287
|
+
* uses the current time and recomputes it every minute; pass it to make the output
|
|
288
|
+
* deterministic (tests, screenshots).
|
|
289
|
+
*/
|
|
290
|
+
now?: Date;
|
|
291
|
+
/** Error text shown with `role="alert"`; overrides a rejection message. */
|
|
292
|
+
error?: string;
|
|
293
|
+
/** Disables every button, for example while sessions load. */
|
|
294
|
+
disabled?: boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Heading text.
|
|
297
|
+
* @default "Where you're signed in"
|
|
298
|
+
*/
|
|
299
|
+
title?: string;
|
|
300
|
+
/**
|
|
301
|
+
* Text under the heading.
|
|
302
|
+
* @default "Sign out of any device you don't recognize."
|
|
303
|
+
*/
|
|
304
|
+
description?: string;
|
|
305
|
+
/**
|
|
306
|
+
* Root testID; child testIDs are derived from it.
|
|
307
|
+
* @default "sessions-card"
|
|
308
|
+
*/
|
|
309
|
+
testID?: string;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* What {@link TwoFactorSettingsCardProps.onStartEnroll} resolves: the TOTP branch of Better
|
|
314
|
+
* Auth's `twoFactor.enable()` data. `enable()` resolves `{method: "otp"}` or
|
|
315
|
+
* `{method: "totp", totpURI, backupCodes}`, so narrow it with `"totpURI" in data` first.
|
|
316
|
+
*/
|
|
317
|
+
export interface TwoFactorEnrollment {
|
|
318
|
+
/**
|
|
319
|
+
* The `otpauth://totp/...` URI the authenticator app scans. The card draws it as a QR code and
|
|
320
|
+
* shows its `secret` parameter for manual entry.
|
|
321
|
+
*/
|
|
322
|
+
totpURI: string;
|
|
323
|
+
/** The single-use backup codes generated with the secret. */
|
|
324
|
+
backupCodes: string[];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Props for the TwoFactorSettingsCard component.
|
|
329
|
+
*/
|
|
330
|
+
export interface TwoFactorSettingsCardProps {
|
|
331
|
+
/**
|
|
332
|
+
* Whether two-factor authentication is on (Better Auth's `user.twoFactorEnabled`). False offers
|
|
333
|
+
* "Turn on"; true offers new backup codes and "Turn off". An enrollment or new-codes flow in
|
|
334
|
+
* progress keeps showing until the user finishes it, even after this flips.
|
|
335
|
+
*/
|
|
336
|
+
enabled: boolean;
|
|
337
|
+
/**
|
|
338
|
+
* How many unused backup codes the user has left. Shown when given, with a warning below 3.
|
|
339
|
+
* Better Auth does not report this on the session; pass it when the app knows it.
|
|
340
|
+
*/
|
|
341
|
+
backupCodesRemaining?: number;
|
|
342
|
+
/**
|
|
343
|
+
* Called after the password step (or at once when `requirePassword` is false) to start
|
|
344
|
+
* enrollment. Call `authClient.twoFactor.enable({password})`; throw when it resolves an `error`
|
|
345
|
+
* (the Better Auth client resolves `{data, error}` instead of rejecting) or data without a
|
|
346
|
+
* `totpURI` (the `{method: "otp"}` branch), else return `{totpURI, backupCodes}` from it.
|
|
347
|
+
* The same applies to every callback below. A rejection shows its message on the step.
|
|
348
|
+
*/
|
|
349
|
+
onStartEnroll: (password?: string) => Promise<TwoFactorEnrollment>;
|
|
350
|
+
/**
|
|
351
|
+
* Called with the code the user typed from their authenticator app. Call
|
|
352
|
+
* `authClient.twoFactor.verifyTotp({code})`, which turns two-factor on once it succeeds. A
|
|
353
|
+
* rejection clears the code and shows its message.
|
|
354
|
+
*/
|
|
355
|
+
onVerify: (code: string) => Promise<void>;
|
|
356
|
+
/**
|
|
357
|
+
* Called after the password step to replace the backup codes. Call
|
|
358
|
+
* `authClient.twoFactor.generateBackupCodes({password})` and return `data.backupCodes`. Hidden
|
|
359
|
+
* when not passed.
|
|
360
|
+
*/
|
|
361
|
+
onRegenerateBackupCodes?: (password?: string) => Promise<string[]>;
|
|
362
|
+
/**
|
|
363
|
+
* Called after the password step and a destructive confirm. Call
|
|
364
|
+
* `authClient.twoFactor.disable({password})`. Hidden when not passed.
|
|
365
|
+
*/
|
|
366
|
+
onDisable?: (password?: string) => Promise<void>;
|
|
367
|
+
/**
|
|
368
|
+
* Asks for the password before enrolling, replacing backup codes, and turning off. Better Auth
|
|
369
|
+
* requires it unless its two-factor plugin sets `allowPasswordless` (Terreno's `twoFactor`
|
|
370
|
+
* config does not), and even then for users who have a password; with `allowPasswordless`,
|
|
371
|
+
* pass `requirePassword={hasPassword}`. When false, callbacks get `undefined`.
|
|
372
|
+
* @default true
|
|
373
|
+
*/
|
|
374
|
+
requirePassword?: boolean;
|
|
375
|
+
/**
|
|
376
|
+
* Whether the user has a password (a `"credential"` account; see `hasPasswordCredential`).
|
|
377
|
+
* With `requirePassword`, a user without one can't confirm, so Turn on, Get new backup codes
|
|
378
|
+
* and Turn off are disabled and the card asks them to set a password first.
|
|
379
|
+
* @default true
|
|
380
|
+
*/
|
|
381
|
+
hasPassword?: boolean;
|
|
382
|
+
/**
|
|
383
|
+
* Digits in an authenticator code: Better Auth's `totpOptions.digits`. Defaults to the
|
|
384
|
+
* `digits` parameter of the enrollment's `totpURI`, else 6.
|
|
385
|
+
*/
|
|
386
|
+
digits?: number;
|
|
387
|
+
/** Error text shown with `role="alert"`; overrides a rejection message. */
|
|
388
|
+
error?: string;
|
|
389
|
+
/**
|
|
390
|
+
* Disables Turn on, Get new backup codes, Turn off and the password step, for example while
|
|
391
|
+
* the user loads.
|
|
392
|
+
*/
|
|
393
|
+
disabled?: boolean;
|
|
394
|
+
/**
|
|
395
|
+
* The signed-in user's email or username. On web it goes in a hidden `autocomplete="username"`
|
|
396
|
+
* field next to the password step so password managers fill the right account's password.
|
|
397
|
+
*/
|
|
398
|
+
username?: string;
|
|
399
|
+
/**
|
|
400
|
+
* Heading text.
|
|
401
|
+
* @default "Two-factor authentication"
|
|
402
|
+
*/
|
|
403
|
+
title?: string;
|
|
404
|
+
/**
|
|
405
|
+
* Text under the heading.
|
|
406
|
+
* @default "Sign in with a code from an authenticator app as well as your password."
|
|
407
|
+
*/
|
|
408
|
+
description?: string;
|
|
409
|
+
/**
|
|
410
|
+
* Root testID; child testIDs are derived from it.
|
|
411
|
+
* @default "two-factor-settings-card"
|
|
412
|
+
*/
|
|
413
|
+
testID?: string;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Props for the AccountSecurityScreen component. Each card renders only when its props are given,
|
|
418
|
+
* so leave out the props of a feature the app has turned off (for example, `passkeys` when the
|
|
419
|
+
* server has no passkey plugin) and its card disappears.
|
|
420
|
+
*/
|
|
421
|
+
export interface AccountSecurityScreenProps {
|
|
422
|
+
/**
|
|
423
|
+
* Props for the LinkedAccountsCard, shown first under "Sign-in methods". Omit to hide the card.
|
|
424
|
+
*/
|
|
425
|
+
linkedAccounts?: LinkedAccountsCardProps;
|
|
426
|
+
/** Props for the PasswordCard, shown after linked accounts. Omit to hide the card. */
|
|
427
|
+
password?: PasswordCardProps;
|
|
428
|
+
/** Props for the PasskeysCard. Omit to hide the card, for example when passkeys are off. */
|
|
429
|
+
passkeys?: PasskeysCardProps;
|
|
430
|
+
/** Props for the TwoFactorSettingsCard. Omit to hide the card, for example when 2FA is off. */
|
|
431
|
+
twoFactor?: TwoFactorSettingsCardProps;
|
|
432
|
+
/** Props for the SessionsCard, shown last. Omit to hide the card. */
|
|
433
|
+
sessions?: SessionsCardProps;
|
|
434
|
+
/**
|
|
435
|
+
* Page heading.
|
|
436
|
+
* @default "Security"
|
|
437
|
+
*/
|
|
438
|
+
title?: string;
|
|
439
|
+
/** Text under the heading. */
|
|
440
|
+
description?: string;
|
|
441
|
+
/**
|
|
442
|
+
* Content under the heading and description and above the cards, such as the signed-in
|
|
443
|
+
* user's name and email or a notice. Shown in every state.
|
|
444
|
+
*/
|
|
445
|
+
header?: ReactNode;
|
|
446
|
+
/**
|
|
447
|
+
* Extra content after the cards, such as an app-specific card. Hidden with the cards while
|
|
448
|
+
* loading or showing `error`.
|
|
449
|
+
*/
|
|
450
|
+
children?: ReactNode;
|
|
451
|
+
/**
|
|
452
|
+
* Shows a spinner instead of the cards, for example while the session, accounts, passkeys and
|
|
453
|
+
* sessions load. Takes precedence over `error`, so a retry in flight shows as loading.
|
|
454
|
+
*/
|
|
455
|
+
isLoading?: boolean;
|
|
456
|
+
/**
|
|
457
|
+
* A page-level error, for example when the data the cards need failed to load. Shown with
|
|
458
|
+
* `role="alert"` instead of the cards. Errors from a card's own action belong in that card's
|
|
459
|
+
* `error` prop.
|
|
460
|
+
*/
|
|
461
|
+
error?: string;
|
|
462
|
+
/** Called by the Try again button under `error`. Without it the button is hidden. */
|
|
463
|
+
onRetry?: () => void;
|
|
464
|
+
/**
|
|
465
|
+
* Wraps the screen in a scrolling ui `Page`. Pass false when the screen sits inside your own
|
|
466
|
+
* `Page`, `ScrollView` or tab layout, so scroll views do not nest.
|
|
467
|
+
* @default true
|
|
468
|
+
*/
|
|
469
|
+
withPage?: boolean;
|
|
470
|
+
/**
|
|
471
|
+
* The widest the content grows, in pixels. Cards stack in one column at any width.
|
|
472
|
+
* @default 720
|
|
473
|
+
*/
|
|
474
|
+
maxWidth?: number;
|
|
475
|
+
/**
|
|
476
|
+
* Root testID; child testIDs are derived from it.
|
|
477
|
+
* @default "account-security-screen"
|
|
478
|
+
*/
|
|
479
|
+
testID?: string;
|
|
480
|
+
}
|