@aws-amplify/ui 5.8.1 → 6.0.1
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/dist/esm/helpers/accountSettings/utils.mjs +33 -1
- package/dist/esm/helpers/accountSettings/validator.mjs +120 -1
- package/dist/esm/helpers/authenticator/actor.mjs +20 -1
- package/dist/esm/helpers/authenticator/constants.mjs +144 -1
- package/dist/esm/helpers/authenticator/defaultAuthHubHandler.mjs +52 -0
- package/dist/esm/helpers/authenticator/facade.mjs +137 -1
- package/dist/esm/helpers/authenticator/form.mjs +43 -1
- package/dist/esm/helpers/authenticator/formFields/defaults.mjs +132 -1
- package/dist/esm/helpers/authenticator/formFields/formFields.mjs +62 -1
- package/dist/esm/helpers/authenticator/formFields/utils.mjs +35 -0
- package/dist/esm/helpers/authenticator/getRoute.mjs +47 -0
- package/dist/esm/helpers/authenticator/textUtil.mjs +112 -1
- package/dist/esm/helpers/authenticator/utils.mjs +38 -1
- package/dist/esm/helpers/utils.mjs +5 -1
- package/dist/esm/i18n/country-dial-codes.mjs +210 -1
- package/dist/esm/i18n/dictionaries/authenticator/de.mjs +87 -1
- package/dist/esm/i18n/dictionaries/authenticator/defaultTexts.mjs +83 -1
- package/dist/esm/i18n/dictionaries/authenticator/en.mjs +74 -1
- package/dist/esm/i18n/dictionaries/authenticator/es.mjs +83 -1
- package/dist/esm/i18n/dictionaries/authenticator/fr.mjs +92 -1
- package/dist/esm/i18n/dictionaries/authenticator/he.mjs +54 -1
- package/dist/esm/i18n/dictionaries/authenticator/id.mjs +96 -1
- package/dist/esm/i18n/dictionaries/authenticator/it.mjs +82 -1
- package/dist/esm/i18n/dictionaries/authenticator/ja.mjs +86 -1
- package/dist/esm/i18n/dictionaries/authenticator/kr.mjs +71 -1
- package/dist/esm/i18n/dictionaries/authenticator/nb.mjs +95 -1
- package/dist/esm/i18n/dictionaries/authenticator/nl.mjs +67 -1
- package/dist/esm/i18n/dictionaries/authenticator/pl.mjs +71 -1
- package/dist/esm/i18n/dictionaries/authenticator/pt.mjs +61 -1
- package/dist/esm/i18n/dictionaries/authenticator/ru.mjs +61 -1
- package/dist/esm/i18n/dictionaries/authenticator/sv.mjs +82 -1
- package/dist/esm/i18n/dictionaries/authenticator/tr.mjs +76 -1
- package/dist/esm/i18n/dictionaries/authenticator/ua.mjs +84 -1
- package/dist/esm/i18n/dictionaries/authenticator/zh.mjs +74 -1
- package/dist/esm/i18n/dictionaries/index.mjs +47 -1
- package/dist/esm/i18n/translations.mjs +67 -1
- package/dist/esm/index.mjs +28 -1
- package/dist/esm/machines/authenticator/actions.mjs +188 -1
- package/dist/esm/machines/authenticator/actors/forgotPassword.mjs +184 -0
- package/dist/esm/machines/authenticator/actors/signIn.mjs +328 -1
- package/dist/esm/machines/authenticator/actors/signOut.mjs +28 -1
- package/dist/esm/machines/authenticator/actors/signUp.mjs +295 -0
- package/dist/esm/machines/authenticator/actors/verifyUserAttributes.mjs +106 -0
- package/dist/esm/machines/authenticator/defaultServices.mjs +102 -1
- package/dist/esm/machines/authenticator/guards.mjs +70 -0
- package/dist/esm/machines/authenticator/index.mjs +368 -1
- package/dist/esm/machines/authenticator/utils.mjs +71 -0
- package/dist/esm/theme/breakpoints.mjs +14 -1
- package/dist/esm/theme/createTheme.mjs +156 -1
- package/dist/esm/theme/defaultDarkModeOverride.mjs +128 -1
- package/dist/esm/theme/defaultTheme.mjs +10 -1
- package/dist/esm/theme/tokens/borderWidths.mjs +7 -1
- package/dist/esm/theme/tokens/colors.mjs +166 -1
- package/dist/esm/theme/tokens/components/accordion.mjs +47 -0
- package/dist/esm/theme/tokens/components/alert.mjs +35 -1
- package/dist/esm/theme/tokens/components/authenticator.mjs +39 -1
- package/dist/esm/theme/tokens/components/autocomplete.mjs +42 -1
- package/dist/esm/theme/tokens/components/badge.mjs +44 -1
- package/dist/esm/theme/tokens/components/breadcrumbs.mjs +34 -1
- package/dist/esm/theme/tokens/components/button.mjs +685 -1
- package/dist/esm/theme/tokens/components/card.mjs +27 -1
- package/dist/esm/theme/tokens/components/checkbox.mjs +87 -1
- package/dist/esm/theme/tokens/components/checkboxField.mjs +8 -1
- package/dist/esm/theme/tokens/components/collection.mjs +72 -1
- package/dist/esm/theme/tokens/components/copy.mjs +18 -1
- package/dist/esm/theme/tokens/components/dialCodeSelect.mjs +7 -1
- package/dist/esm/theme/tokens/components/divider.mjs +22 -1
- package/dist/esm/theme/tokens/components/dropZone.mjs +46 -1
- package/dist/esm/theme/tokens/components/field.mjs +20 -1
- package/dist/esm/theme/tokens/components/fieldControl.mjs +131 -1
- package/dist/esm/theme/tokens/components/fieldGroup.mjs +11 -1
- package/dist/esm/theme/tokens/components/fieldMessages.mjs +13 -1
- package/dist/esm/theme/tokens/components/fieldset.mjs +40 -1
- package/dist/esm/theme/tokens/components/flex.mjs +9 -1
- package/dist/esm/theme/tokens/components/heading.mjs +30 -1
- package/dist/esm/theme/tokens/components/highlightMatch.mjs +7 -1
- package/dist/esm/theme/tokens/components/icon.mjs +6 -1
- package/dist/esm/theme/tokens/components/image.mjs +8 -1
- package/dist/esm/theme/tokens/components/inAppMessaging.mjs +23 -1
- package/dist/esm/theme/tokens/components/index.mjs +111 -1
- package/dist/esm/theme/tokens/components/input.mjs +12 -1
- package/dist/esm/theme/tokens/components/link.mjs +9 -1
- package/dist/esm/theme/tokens/components/liveness.mjs +7 -1
- package/dist/esm/theme/tokens/components/loader.mjs +42 -1
- package/dist/esm/theme/tokens/components/menu.mjs +27 -1
- package/dist/esm/theme/tokens/components/message.mjs +102 -1
- package/dist/esm/theme/tokens/components/pagination.mjs +40 -1
- package/dist/esm/theme/tokens/components/passwordField.mjs +38 -1
- package/dist/esm/theme/tokens/components/phoneNumberField.mjs +10 -1
- package/dist/esm/theme/tokens/components/placeholder.mjs +18 -1
- package/dist/esm/theme/tokens/components/radio.mjs +67 -1
- package/dist/esm/theme/tokens/components/radioGroup.mjs +19 -1
- package/dist/esm/theme/tokens/components/rating.mjs +9 -1
- package/dist/esm/theme/tokens/components/searchField.mjs +39 -1
- package/dist/esm/theme/tokens/components/select.mjs +63 -1
- package/dist/esm/theme/tokens/components/selectField.mjs +16 -1
- package/dist/esm/theme/tokens/components/sliderField.mjs +70 -1
- package/dist/esm/theme/tokens/components/stepperField.mjs +33 -1
- package/dist/esm/theme/tokens/components/storagemanager.mjs +97 -1
- package/dist/esm/theme/tokens/components/switchField.mjs +61 -1
- package/dist/esm/theme/tokens/components/table.mjs +105 -1
- package/dist/esm/theme/tokens/components/tabs.mjs +59 -1
- package/dist/esm/theme/tokens/components/text.mjs +28 -1
- package/dist/esm/theme/tokens/components/textAreaField.mjs +11 -1
- package/dist/esm/theme/tokens/components/textField.mjs +12 -1
- package/dist/esm/theme/tokens/components/toggleButton.mjs +96 -1
- package/dist/esm/theme/tokens/components/toggleButtonGroup.mjs +7 -1
- package/dist/esm/theme/tokens/fontSizes.mjs +14 -1
- package/dist/esm/theme/tokens/fontWeights.mjs +13 -1
- package/dist/esm/theme/tokens/fonts.mjs +19 -1
- package/dist/esm/theme/tokens/index.mjs +65 -1
- package/dist/esm/theme/tokens/lineHeights.mjs +7 -1
- package/dist/esm/theme/tokens/opacities.mjs +15 -1
- package/dist/esm/theme/tokens/outlineOffsets.mjs +7 -1
- package/dist/esm/theme/tokens/outlineWidths.mjs +7 -1
- package/dist/esm/theme/tokens/radii.mjs +11 -1
- package/dist/esm/theme/tokens/shadows.mjs +28 -1
- package/dist/esm/theme/tokens/space.mjs +29 -1
- package/dist/esm/theme/tokens/time.mjs +7 -1
- package/dist/esm/theme/tokens/transforms.mjs +10 -1
- package/dist/esm/theme/utils.mjs +81 -1
- package/dist/esm/types/authenticator/attributes.mjs +41 -1
- package/dist/esm/types/authenticator/user.mjs +18 -1
- package/dist/esm/types/authenticator/utils.mjs +5 -1
- package/dist/esm/types/primitives/componentClassName.mjs +164 -1
- package/dist/esm/utils/classNames.mjs +39 -0
- package/dist/esm/utils/setUserAgent/constants.mjs +43 -0
- package/dist/esm/utils/setUserAgent/setUserAgent.mjs +65 -0
- package/dist/esm/utils/utils.mjs +227 -0
- package/dist/esm/validators/index.mjs +19 -1
- package/dist/index.js +8396 -1
- package/dist/styles/StorageManager.css +138 -0
- package/dist/styles/StorageManager.layer.css +140 -0
- package/dist/styles/_fieldControl.css +0 -0
- package/dist/styles/_fieldControl.layer.css +3 -0
- package/dist/styles/accordion.css +64 -0
- package/dist/styles/accordion.layer.css +66 -0
- package/dist/styles/alert.css +44 -0
- package/dist/styles/alert.layer.css +46 -0
- package/dist/styles/authenticator.css +72 -0
- package/dist/styles/authenticator.layer.css +74 -0
- package/dist/styles/autocomplete.css +48 -0
- package/dist/styles/autocomplete.layer.css +50 -0
- package/dist/styles/badge.css +35 -0
- package/dist/styles/badge.layer.css +37 -0
- package/dist/styles/base.css +1491 -0
- package/dist/styles/base.layer.css +1493 -0
- package/dist/styles/breadcrumbs.css +40 -0
- package/dist/styles/breadcrumbs.layer.css +42 -0
- package/dist/styles/button.css +1122 -0
- package/dist/styles/button.layer.css +1124 -0
- package/dist/styles/card.css +26 -0
- package/dist/styles/card.layer.css +28 -0
- package/dist/styles/checkbox.css +95 -0
- package/dist/styles/checkbox.layer.css +97 -0
- package/dist/styles/checkboxField.css +6 -0
- package/dist/styles/checkboxField.layer.css +8 -0
- package/dist/styles/collection.css +70 -0
- package/dist/styles/collection.layer.css +72 -0
- package/dist/styles/copy.css +27 -0
- package/dist/styles/copy.layer.css +29 -0
- package/dist/styles/dialCodeSelect.css +3 -0
- package/dist/styles/dialCodeSelect.layer.css +5 -0
- package/dist/styles/divider.css +47 -0
- package/dist/styles/divider.layer.css +49 -0
- package/dist/styles/dropZone.css +45 -0
- package/dist/styles/dropZone.layer.css +47 -0
- package/dist/styles/field.css +17 -0
- package/dist/styles/field.layer.css +19 -0
- package/dist/styles/fieldGroup.css +130 -0
- package/dist/styles/fieldGroup.layer.css +132 -0
- package/dist/styles/fieldMessages.css +10 -0
- package/dist/styles/fieldMessages.layer.css +12 -0
- package/dist/styles/fieldModifiers.css +15 -0
- package/dist/styles/fieldModifiers.layer.css +17 -0
- package/dist/styles/fieldset.css +37 -0
- package/dist/styles/fieldset.layer.css +39 -0
- package/dist/styles/flex.css +8 -0
- package/dist/styles/flex.layer.css +10 -0
- package/dist/styles/grid.css +3 -0
- package/dist/styles/grid.layer.css +5 -0
- package/dist/styles/heading.css +40 -0
- package/dist/styles/heading.layer.css +42 -0
- package/dist/styles/highlightMatch.css +3 -0
- package/dist/styles/highlightMatch.layer.css +5 -0
- package/dist/styles/icon.css +14 -0
- package/dist/styles/icon.layer.css +16 -0
- package/dist/styles/image.css +9 -0
- package/dist/styles/image.layer.css +11 -0
- package/dist/styles/inAppMessaging.css +179 -0
- package/dist/styles/inAppMessaging.layer.css +181 -0
- package/dist/styles/input.css +83 -0
- package/dist/styles/input.layer.css +85 -0
- package/dist/styles/link.css +26 -0
- package/dist/styles/link.layer.css +28 -0
- package/dist/styles/liveness.css +423 -0
- package/dist/styles/liveness.layer.css +425 -0
- package/dist/styles/loader.css +108 -0
- package/dist/styles/loader.layer.css +110 -0
- package/dist/styles/menu.css +54 -0
- package/dist/styles/menu.layer.css +56 -0
- package/dist/styles/message.css +111 -0
- package/dist/styles/message.layer.css +113 -0
- package/dist/styles/pagination.css +41 -0
- package/dist/styles/pagination.layer.css +43 -0
- package/dist/styles/passwordField.css +49 -0
- package/dist/styles/passwordField.layer.css +51 -0
- package/dist/styles/phoneNumberField.css +30 -0
- package/dist/styles/phoneNumberField.layer.css +32 -0
- package/dist/styles/placeholder.css +31 -0
- package/dist/styles/placeholder.layer.css +33 -0
- package/dist/styles/radio.css +82 -0
- package/dist/styles/radio.layer.css +84 -0
- package/dist/styles/radioGroupField.css +25 -0
- package/dist/styles/radioGroupField.layer.css +27 -0
- package/dist/styles/radiogroup.css +5 -0
- package/dist/styles/radiogroup.layer.css +7 -0
- package/dist/styles/rating.css +33 -0
- package/dist/styles/rating.layer.css +35 -0
- package/dist/styles/reset.css +76 -0
- package/dist/styles/reset.layer.css +78 -0
- package/dist/styles/scrollView.css +4 -0
- package/dist/styles/scrollView.layer.css +6 -0
- package/dist/styles/searchField.css +29 -0
- package/dist/styles/searchField.layer.css +31 -0
- package/dist/styles/select.css +128 -0
- package/dist/styles/select.layer.css +130 -0
- package/dist/styles/selectField.css +18 -0
- package/dist/styles/selectField.layer.css +20 -0
- package/dist/styles/sliderField.css +143 -0
- package/dist/styles/sliderField.layer.css +145 -0
- package/dist/styles/stepperField.css +77 -0
- package/dist/styles/stepperField.layer.css +79 -0
- package/dist/styles/switchField.css +76 -0
- package/dist/styles/switchField.layer.css +78 -0
- package/dist/styles/table.css +146 -0
- package/dist/styles/table.layer.css +148 -0
- package/dist/styles/tabs.css +87 -0
- package/dist/styles/tabs.layer.css +89 -0
- package/dist/styles/text.css +40 -0
- package/dist/styles/text.layer.css +42 -0
- package/dist/styles/textArea.css +71 -0
- package/dist/styles/textArea.layer.css +73 -0
- package/dist/styles/textAreaField.css +12 -0
- package/dist/styles/textAreaField.layer.css +14 -0
- package/dist/styles/textField.css +14 -0
- package/dist/styles/textField.layer.css +16 -0
- package/dist/styles/toggleButton.css +280 -0
- package/dist/styles/toggleButton.layer.css +282 -0
- package/dist/styles/toggleButtonGroup.css +31 -0
- package/dist/styles/toggleButtonGroup.layer.css +33 -0
- package/dist/styles/visuallyHidden.css +12 -0
- package/dist/styles/visuallyHidden.layer.css +14 -0
- package/dist/styles.css +343 -680
- package/dist/styles.layer.css +6164 -0
- package/dist/theme.css +93 -156
- package/dist/types/helpers/accountSettings/utils.d.ts +1 -3
- package/dist/types/helpers/authenticator/actor.d.ts +1 -1
- package/dist/types/helpers/authenticator/constants.d.ts +5 -0
- package/dist/types/helpers/authenticator/defaultAuthHubHandler.d.ts +15 -0
- package/dist/types/helpers/authenticator/facade.d.ts +35 -6
- package/dist/types/helpers/authenticator/formFields/defaults.d.ts +3 -1
- package/dist/types/helpers/authenticator/formFields/formFields.d.ts +2 -1
- package/dist/types/helpers/authenticator/formFields/index.d.ts +1 -1
- package/dist/types/helpers/authenticator/formFields/{util.d.ts → utils.d.ts} +2 -0
- package/dist/types/helpers/authenticator/getRoute.d.ts +2 -0
- package/dist/types/helpers/authenticator/index.d.ts +2 -1
- package/dist/types/helpers/authenticator/textUtil.d.ts +8 -7
- package/dist/types/{types/authenticator/stateMachine/authMachine.d.ts → helpers/authenticator/types.d.ts} +5 -5
- package/dist/types/helpers/authenticator/utils.d.ts +0 -25
- package/dist/types/helpers/index.d.ts +0 -1
- package/dist/types/helpers/utils.d.ts +2 -2
- package/dist/types/i18n/translations.d.ts +2 -3
- package/dist/types/machines/authenticator/actions.d.ts +4 -62
- package/dist/types/machines/authenticator/actors/{resetPassword.d.ts → forgotPassword.d.ts} +3 -3
- package/dist/types/machines/authenticator/actors/index.d.ts +3 -1
- package/dist/types/machines/authenticator/actors/signIn.d.ts +3 -3
- package/dist/types/machines/authenticator/actors/signOut.d.ts +2 -2
- package/dist/types/machines/authenticator/{signUp.d.ts → actors/signUp.d.ts} +3 -3
- package/dist/types/machines/authenticator/actors/verifyUserAttributes.d.ts +5 -0
- package/dist/types/machines/authenticator/defaultServices.d.ts +208 -28
- package/dist/types/machines/authenticator/getAuthenticatorConfig.d.ts +14 -0
- package/dist/types/machines/authenticator/guards.d.ts +4 -0
- package/dist/types/machines/authenticator/index.d.ts +4 -2
- package/dist/types/machines/authenticator/types.d.ts +125 -0
- package/dist/types/machines/authenticator/utils.d.ts +7 -0
- package/dist/types/machines/index.d.ts +1 -0
- package/dist/types/theme/tokens/borderWidths.d.ts +2 -2
- package/dist/types/theme/tokens/colors.d.ts +7 -9
- package/dist/types/theme/tokens/components/accordion.d.ts +12 -0
- package/dist/types/theme/tokens/components/index.d.ts +2 -4
- package/dist/types/theme/tokens/components/radioGroup.d.ts +1 -1
- package/dist/types/theme/tokens/components/storagemanager.d.ts +18 -3
- package/dist/types/theme/tokens/components/tabs.d.ts +4 -3
- package/dist/types/theme/tokens/fontSizes.d.ts +2 -2
- package/dist/types/theme/tokens/fontWeights.d.ts +2 -2
- package/dist/types/theme/tokens/fonts.d.ts +2 -2
- package/dist/types/theme/tokens/lineHeights.d.ts +2 -2
- package/dist/types/theme/tokens/opacities.d.ts +2 -2
- package/dist/types/theme/tokens/outlineOffsets.d.ts +2 -2
- package/dist/types/theme/tokens/outlineWidths.d.ts +2 -2
- package/dist/types/theme/tokens/radii.d.ts +2 -2
- package/dist/types/theme/tokens/shadows.d.ts +2 -2
- package/dist/types/theme/tokens/space.d.ts +2 -2
- package/dist/types/theme/tokens/time.d.ts +2 -2
- package/dist/types/theme/tokens/types/designToken.d.ts +12 -6
- package/dist/types/theme/types.d.ts +5 -1
- package/dist/types/types/authenticator/attributes.d.ts +10 -4
- package/dist/types/types/authenticator/form.d.ts +7 -6
- package/dist/types/types/authenticator/index.d.ts +0 -1
- package/dist/types/types/authenticator/user.d.ts +3 -29
- package/dist/types/types/authenticator/validator.d.ts +2 -2
- package/dist/types/types/displayText.d.ts +84 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/primitives/componentClassName.d.ts +162 -180
- package/dist/types/types/util.d.ts +0 -5
- package/dist/types/utils/classNames.d.ts +4 -0
- package/dist/types/utils/index.d.ts +3 -135
- package/dist/types/utils/setUserAgent/constants.d.ts +7 -0
- package/dist/types/utils/setUserAgent/index.d.ts +1 -0
- package/dist/types/utils/setUserAgent/setUserAgent.d.ts +19 -0
- package/dist/types/utils/utils.d.ts +147 -0
- package/dist/types/validators/index.d.ts +2 -2
- package/package.json +5 -19
- package/dist/esm/helpers/authenticator/context.mjs +0 -1
- package/dist/esm/helpers/authenticator/formFields/util.mjs +0 -1
- package/dist/esm/helpers/storage/fileUploader/utils/uploader.mjs +0 -1
- package/dist/esm/machines/authenticator/actors/resetPassword.mjs +0 -1
- package/dist/esm/machines/authenticator/signUp.mjs +0 -1
- package/dist/esm/theme/tokens/components/expander.mjs +0 -1
- package/dist/esm/theme/tokens/components/fileUploader.mjs +0 -1
- package/dist/esm/utils/index.mjs +0 -1
- package/dist/types/helpers/authenticator/context.d.ts +0 -13
- package/dist/types/helpers/storage/fileUploader/index.d.ts +0 -1
- package/dist/types/helpers/storage/fileUploader/utils/index.d.ts +0 -1
- package/dist/types/helpers/storage/fileUploader/utils/uploader.d.ts +0 -28
- package/dist/types/helpers/storage/index.d.ts +0 -1
- package/dist/types/theme/tokens/components/expander.d.ts +0 -22
- package/dist/types/theme/tokens/components/fileUploader.d.ts +0 -23
- package/dist/types/types/authenticator/stateMachine/context.d.ts +0 -109
- package/dist/types/types/authenticator/stateMachine/event.d.ts +0 -17
- package/dist/types/types/authenticator/stateMachine/index.d.ts +0 -4
- package/dist/types/types/authenticator/stateMachine/state.d.ts +0 -10
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createMachine, sendUpdate } from 'xstate';
|
|
2
|
+
import { sendUserAttributeVerificationCode, confirmUserAttribute } from 'aws-amplify/auth';
|
|
3
|
+
import { runValidators } from '../../../validators/index.mjs';
|
|
4
|
+
import ACTIONS from '../actions.mjs';
|
|
5
|
+
import { defaultServices } from '../defaultServices.mjs';
|
|
6
|
+
|
|
7
|
+
function verifyUserAttributesActor() {
|
|
8
|
+
return createMachine({
|
|
9
|
+
id: 'verifyUserAttributesActor',
|
|
10
|
+
initial: 'selectUserAttributes',
|
|
11
|
+
predictableActionArguments: true,
|
|
12
|
+
states: {
|
|
13
|
+
selectUserAttributes: {
|
|
14
|
+
initial: 'edit',
|
|
15
|
+
exit: ['clearError', 'clearTouched', 'sendUpdate'],
|
|
16
|
+
states: {
|
|
17
|
+
edit: {
|
|
18
|
+
entry: 'sendUpdate',
|
|
19
|
+
on: {
|
|
20
|
+
SUBMIT: { actions: 'handleSubmit', target: 'submit' },
|
|
21
|
+
SKIP: { target: '#verifyUserAttributesActor.resolved' },
|
|
22
|
+
CHANGE: { actions: 'handleInput' },
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
submit: {
|
|
26
|
+
tags: 'pending',
|
|
27
|
+
entry: ['clearError', 'sendUpdate'],
|
|
28
|
+
invoke: {
|
|
29
|
+
src: 'sendUserAttributeVerificationCode',
|
|
30
|
+
onDone: {
|
|
31
|
+
actions: [
|
|
32
|
+
'setSelectedUserAttribute',
|
|
33
|
+
'setCodeDeliveryDetails',
|
|
34
|
+
],
|
|
35
|
+
target: '#verifyUserAttributesActor.confirmVerifyUserAttribute',
|
|
36
|
+
},
|
|
37
|
+
onError: {
|
|
38
|
+
actions: 'setRemoteError',
|
|
39
|
+
target: 'edit',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
confirmVerifyUserAttribute: {
|
|
46
|
+
initial: 'edit',
|
|
47
|
+
exit: ['clearError', 'clearFormValues', 'clearTouched'],
|
|
48
|
+
states: {
|
|
49
|
+
edit: {
|
|
50
|
+
entry: 'sendUpdate',
|
|
51
|
+
on: {
|
|
52
|
+
SUBMIT: { actions: 'handleSubmit', target: 'submit' },
|
|
53
|
+
SKIP: '#verifyUserAttributesActor.resolved',
|
|
54
|
+
CHANGE: { actions: 'handleInput' },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
submit: {
|
|
58
|
+
tags: 'pending',
|
|
59
|
+
entry: ['clearError', 'sendUpdate'],
|
|
60
|
+
invoke: {
|
|
61
|
+
src: 'confirmVerifyUserAttribute',
|
|
62
|
+
onDone: {
|
|
63
|
+
actions: [
|
|
64
|
+
'setConfirmAttributeCompleteStep',
|
|
65
|
+
'clearSelectedUserAttribute',
|
|
66
|
+
],
|
|
67
|
+
target: '#verifyUserAttributesActor.resolved',
|
|
68
|
+
},
|
|
69
|
+
onError: {
|
|
70
|
+
actions: 'setRemoteError',
|
|
71
|
+
target: 'edit',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
resolved: { type: 'final', data: ({ step }) => ({ step }) },
|
|
78
|
+
},
|
|
79
|
+
}, {
|
|
80
|
+
// sendUpdate is a HOC
|
|
81
|
+
actions: { ...ACTIONS, sendUpdate: sendUpdate() },
|
|
82
|
+
services: {
|
|
83
|
+
sendUserAttributeVerificationCode({ formValues: { unverifiedAttr } }) {
|
|
84
|
+
const input = {
|
|
85
|
+
userAttributeKey: unverifiedAttr,
|
|
86
|
+
};
|
|
87
|
+
return sendUserAttributeVerificationCode(input);
|
|
88
|
+
},
|
|
89
|
+
async confirmVerifyUserAttribute({ formValues: { confirmation_code: confirmationCode }, selectedUserAttribute, }) {
|
|
90
|
+
const input = {
|
|
91
|
+
confirmationCode,
|
|
92
|
+
userAttributeKey: selectedUserAttribute,
|
|
93
|
+
};
|
|
94
|
+
return confirmUserAttribute(input);
|
|
95
|
+
},
|
|
96
|
+
async validateFields(context) {
|
|
97
|
+
return runValidators(context.formValues, context.touched, context.passwordSettings, [
|
|
98
|
+
defaultServices.validateFormPassword,
|
|
99
|
+
defaultServices.validateConfirmPassword,
|
|
100
|
+
]);
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { verifyUserAttributesActor };
|
|
@@ -1 +1,102 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { Amplify } from 'aws-amplify';
|
|
2
|
+
import { getCurrentUser, signIn, signUp, confirmSignIn, confirmSignUp, confirmResetPassword, resetPassword } from 'aws-amplify/auth';
|
|
3
|
+
import 'aws-amplify/utils';
|
|
4
|
+
import '@aws-amplify/core/internals/utils';
|
|
5
|
+
import '../../utils/setUserAgent/constants.mjs';
|
|
6
|
+
import '../../types/authenticator/user.mjs';
|
|
7
|
+
import '../../types/authenticator/attributes.mjs';
|
|
8
|
+
import { hasSpecialChars } from '../../helpers/authenticator/utils.mjs';
|
|
9
|
+
import '../../helpers/accountSettings/utils.mjs';
|
|
10
|
+
|
|
11
|
+
// Cognito does not allow a password length less then 8 characters
|
|
12
|
+
const DEFAULT_COGNITO_PASSWORD_MIN_LENGTH = 8;
|
|
13
|
+
const defaultServices = {
|
|
14
|
+
async getAmplifyConfig() {
|
|
15
|
+
const result = Amplify.getConfig();
|
|
16
|
+
const cliConfig = result.Auth?.Cognito;
|
|
17
|
+
const { loginWith, userAttributes } = result.Auth?.Cognito ?? {};
|
|
18
|
+
const parsedLoginMechanisms = loginWith
|
|
19
|
+
? Object.entries(loginWith)
|
|
20
|
+
.filter(([key, _value]) => key !== 'oauth')
|
|
21
|
+
.filter(([_key, value]) => !!value)
|
|
22
|
+
.map((keyValueArray) => {
|
|
23
|
+
return keyValueArray[0] === 'phone' // the key for phone_number is phone in getConfig but everywhere else we treat is as phone_number
|
|
24
|
+
? 'phone_number'
|
|
25
|
+
: keyValueArray[0];
|
|
26
|
+
})
|
|
27
|
+
: undefined;
|
|
28
|
+
const parsedSignupAttributes = userAttributes
|
|
29
|
+
? Object.entries(userAttributes).map(([_key, value]) => Object.keys(value)[0])
|
|
30
|
+
: undefined;
|
|
31
|
+
const parsedSocialProviders = loginWith?.oauth?.providers
|
|
32
|
+
? loginWith.oauth.providers?.map((provider) => provider.toString().toLowerCase())
|
|
33
|
+
: undefined;
|
|
34
|
+
return {
|
|
35
|
+
...cliConfig,
|
|
36
|
+
loginMechanisms: parsedLoginMechanisms,
|
|
37
|
+
signUpAttributes: parsedSignupAttributes,
|
|
38
|
+
socialProviders: parsedSocialProviders,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
getCurrentUser,
|
|
42
|
+
handleSignIn: signIn,
|
|
43
|
+
handleSignUp: signUp,
|
|
44
|
+
handleConfirmSignIn: confirmSignIn,
|
|
45
|
+
handleConfirmSignUp: confirmSignUp,
|
|
46
|
+
handleForgotPasswordSubmit: confirmResetPassword,
|
|
47
|
+
handleForgotPassword: resetPassword,
|
|
48
|
+
// Validation hooks for overriding
|
|
49
|
+
async validateCustomSignUp(formData, touchData) { },
|
|
50
|
+
async validateFormPassword(formData, touchData, passwordSettings) {
|
|
51
|
+
const { password } = formData;
|
|
52
|
+
const { password: touched_password } = touchData;
|
|
53
|
+
/**
|
|
54
|
+
* If the password is not touched,
|
|
55
|
+
* or if the password settings are not set, we don't need to validate it.
|
|
56
|
+
*/
|
|
57
|
+
if (!touched_password || !passwordSettings)
|
|
58
|
+
return null;
|
|
59
|
+
const password_complexity = [];
|
|
60
|
+
const policyMinLength = passwordSettings.minLength ?? DEFAULT_COGNITO_PASSWORD_MIN_LENGTH;
|
|
61
|
+
if (password.length < policyMinLength) {
|
|
62
|
+
password_complexity.push(`Password must have at least ${policyMinLength} characters`);
|
|
63
|
+
}
|
|
64
|
+
if (passwordSettings.requireLowercase && !/[a-z]/.test(password))
|
|
65
|
+
password_complexity.push('Password must have lower case letters');
|
|
66
|
+
if (passwordSettings.requireUppercase && !/[A-Z]/.test(password))
|
|
67
|
+
password_complexity.push('Password must have upper case letters');
|
|
68
|
+
if (passwordSettings.requireNumbers && !/[0-9]/.test(password))
|
|
69
|
+
password_complexity.push('Password must have numbers');
|
|
70
|
+
// https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-policies.html
|
|
71
|
+
if (passwordSettings.requireSpecialCharacters && !hasSpecialChars(password))
|
|
72
|
+
password_complexity.push('Password must have special characters');
|
|
73
|
+
/**
|
|
74
|
+
* Only return an error if there is at least one error.
|
|
75
|
+
*/
|
|
76
|
+
return password_complexity.length !== 0
|
|
77
|
+
? { password: password_complexity }
|
|
78
|
+
: null;
|
|
79
|
+
},
|
|
80
|
+
async validateConfirmPassword(formData, touchData) {
|
|
81
|
+
const { password, confirm_password } = formData;
|
|
82
|
+
const { confirm_password: touched_confirm_password, password: touched_password, } = touchData;
|
|
83
|
+
if (!password && !confirm_password) {
|
|
84
|
+
// these inputs are clean, don't complain yet
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
else if ((password || confirm_password) &&
|
|
88
|
+
password !== confirm_password &&
|
|
89
|
+
((touched_confirm_password && touched_password) ||
|
|
90
|
+
(password?.length >= 6 && confirm_password?.length >= 6))) {
|
|
91
|
+
// Only return an error if both fields have text entered,
|
|
92
|
+
// the passwords do not match, and the fields have been
|
|
93
|
+
// touched or the password and confirm password is longer then or equal to 6.
|
|
94
|
+
return {
|
|
95
|
+
confirm_password: 'Your passwords must match',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
async validatePreferredUsername(formData, touchData) { },
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export { defaultServices };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const SIGN_IN_STEP_MFA_CONFIRMATION = [
|
|
2
|
+
'CONFIRM_SIGN_IN_WITH_SMS_CODE',
|
|
3
|
+
'CONFIRM_SIGN_IN_WITH_TOTP_CODE',
|
|
4
|
+
];
|
|
5
|
+
// response next step guards
|
|
6
|
+
const shouldConfirmSignInWithNewPassword = (_, { data }) => data?.nextStep.signInStep ===
|
|
7
|
+
'CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED';
|
|
8
|
+
const shouldResetPasswordFromSignIn = (_, { data }) => data?.nextStep?.signInStep === 'RESET_PASSWORD';
|
|
9
|
+
const shouldConfirmSignUpFromSignIn = (_, { data }) => data?.nextStep.signInStep === 'CONFIRM_SIGN_UP';
|
|
10
|
+
const shouldAutoSignIn = (_, { data }) => data?.nextStep.signUpStep === 'COMPLETE_AUTO_SIGN_IN';
|
|
11
|
+
const hasCompletedSignIn = (_, { data }) => data?.nextStep.signInStep === 'DONE';
|
|
12
|
+
const hasCompletedSignUp = (_, { data }) => data?.nextStep.signUpStep === 'DONE';
|
|
13
|
+
const hasCompletedResetPassword = (_, { data }) => data?.nextStep.resetPasswordStep === 'DONE';
|
|
14
|
+
// actor done guards read `step` from actor exit event
|
|
15
|
+
const hasCompletedAttributeConfirmation = (_, { data }) => data?.step === 'CONFIRM_ATTRIBUTE_COMPLETE';
|
|
16
|
+
const isConfirmUserAttributeStep = (_, { data }) => data?.step === 'CONFIRM_ATTRIBUTE_WITH_CODE';
|
|
17
|
+
const isShouldConfirmUserAttributeStep = (_, { data }) => data?.step === 'SHOULD_CONFIRM_USER_ATTRIBUTE';
|
|
18
|
+
const isResetPasswordStep = (_, { data }) => data?.step === 'RESET_PASSWORD';
|
|
19
|
+
const isConfirmSignUpStep = (_, { data }) => data?.step === 'CONFIRM_SIGN_UP';
|
|
20
|
+
// actor entry guards read `step` from actor context
|
|
21
|
+
const shouldConfirmSignIn = ({ step }) => SIGN_IN_STEP_MFA_CONFIRMATION.includes(step);
|
|
22
|
+
const shouldSetupTotp = ({ step }) => step === 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP';
|
|
23
|
+
const shouldResetPassword = ({ step }) => step === 'RESET_PASSWORD';
|
|
24
|
+
const shouldConfirmResetPassword = ({ step }) => step === 'CONFIRM_RESET_PASSWORD_WITH_CODE';
|
|
25
|
+
const shouldConfirmSignUp = ({ step }) => step === 'CONFIRM_SIGN_UP';
|
|
26
|
+
// miscellaneous guards
|
|
27
|
+
const shouldVerifyAttribute = (_, { data }) => {
|
|
28
|
+
const { phone_number_verified, email_verified } = data;
|
|
29
|
+
// email/phone_verified is returned as a string
|
|
30
|
+
const emailNotVerified = email_verified === undefined || email_verified === 'false';
|
|
31
|
+
const phoneNotVerified = phone_number_verified === undefined || phone_number_verified === 'false';
|
|
32
|
+
// only request verification if both email and phone are not verified
|
|
33
|
+
return emailNotVerified && phoneNotVerified;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* This guard covers an edge case that exists in the current state of the UI.
|
|
37
|
+
* As of now, our ConfirmSignUp screen only supports showing an input for a
|
|
38
|
+
* confirmation code. However, a Cognito UserPool can instead verify users
|
|
39
|
+
* through a link that gets emailed to them. If a user verifies through the
|
|
40
|
+
* link and then they click on the "Resend Code" button, they will get an error
|
|
41
|
+
* saying that the user has already been confirmed. If we encounter that error,
|
|
42
|
+
* we want to just funnel them through the rest of the flow. In the future, we will
|
|
43
|
+
* want to update our UI to support both confirmation codes and links.
|
|
44
|
+
*
|
|
45
|
+
* https://github.com/aws-amplify/amplify-ui/issues/219
|
|
46
|
+
*/
|
|
47
|
+
const isUserAlreadyConfirmed = (_, { data }) => data.message === 'User is already confirmed.';
|
|
48
|
+
const GUARDS = {
|
|
49
|
+
hasCompletedAttributeConfirmation,
|
|
50
|
+
hasCompletedResetPassword,
|
|
51
|
+
hasCompletedSignIn,
|
|
52
|
+
hasCompletedSignUp,
|
|
53
|
+
isConfirmSignUpStep,
|
|
54
|
+
isConfirmUserAttributeStep,
|
|
55
|
+
isResetPasswordStep,
|
|
56
|
+
isShouldConfirmUserAttributeStep,
|
|
57
|
+
isUserAlreadyConfirmed,
|
|
58
|
+
shouldAutoSignIn,
|
|
59
|
+
shouldConfirmResetPassword,
|
|
60
|
+
shouldConfirmSignIn,
|
|
61
|
+
shouldConfirmSignInWithNewPassword,
|
|
62
|
+
shouldConfirmSignUp,
|
|
63
|
+
shouldConfirmSignUpFromSignIn,
|
|
64
|
+
shouldResetPassword,
|
|
65
|
+
shouldResetPasswordFromSignIn,
|
|
66
|
+
shouldSetupTotp,
|
|
67
|
+
shouldVerifyAttribute,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { GUARDS as default };
|
|
@@ -1 +1,368 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { createMachine, forwardTo, assign, spawn, actions } from 'xstate';
|
|
2
|
+
import '@aws-amplify/core/internals/utils';
|
|
3
|
+
import '../../utils/setUserAgent/constants.mjs';
|
|
4
|
+
import { isEmptyObject } from '../../utils/utils.mjs';
|
|
5
|
+
import ACTIONS from './actions.mjs';
|
|
6
|
+
import GUARDS from './guards.mjs';
|
|
7
|
+
import { forgotPasswordActor } from './actors/forgotPassword.mjs';
|
|
8
|
+
import { signInActor } from './actors/signIn.mjs';
|
|
9
|
+
import { signUpActor } from './actors/signUp.mjs';
|
|
10
|
+
import { signOutActor } from './actors/signOut.mjs';
|
|
11
|
+
import { verifyUserAttributesActor } from './actors/verifyUserAttributes.mjs';
|
|
12
|
+
import { defaultServices } from './defaultServices.mjs';
|
|
13
|
+
|
|
14
|
+
const getActorContext = (context, defaultStep) => ({
|
|
15
|
+
...context.actorDoneData,
|
|
16
|
+
step: context?.actorDoneData?.step ?? defaultStep,
|
|
17
|
+
// initialize empty objects on actor start
|
|
18
|
+
formValues: {},
|
|
19
|
+
touched: {},
|
|
20
|
+
validationError: {},
|
|
21
|
+
// values included on `context.config` that should be available in actors
|
|
22
|
+
formFields: context.config?.formFields,
|
|
23
|
+
loginMechanisms: context.config?.loginMechanisms,
|
|
24
|
+
passwordSettings: context.config?.passwordSettings,
|
|
25
|
+
signUpAttributes: context.config?.signUpAttributes,
|
|
26
|
+
socialProviders: context.config?.socialProviders,
|
|
27
|
+
});
|
|
28
|
+
const { choose, stop } = actions;
|
|
29
|
+
const stopActor = (machineId) => stop(machineId);
|
|
30
|
+
// setup step waits for ui to emit INIT action to proceed to configure
|
|
31
|
+
const LEGACY_WAIT_CONFIG = {
|
|
32
|
+
on: {
|
|
33
|
+
INIT: {
|
|
34
|
+
actions: ['configure'],
|
|
35
|
+
target: 'getConfig',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
// setup step proceeds directly to configure
|
|
40
|
+
const NEXT_WAIT_CONFIG = {
|
|
41
|
+
always: { actions: ['configure'], target: 'getConfig' },
|
|
42
|
+
};
|
|
43
|
+
function createAuthenticatorMachine(options) {
|
|
44
|
+
const { useNextWaitConfig, ...overrideConfigServices } = options ?? {};
|
|
45
|
+
const initConfig = useNextWaitConfig ? NEXT_WAIT_CONFIG : LEGACY_WAIT_CONFIG;
|
|
46
|
+
return createMachine({
|
|
47
|
+
id: 'authenticator',
|
|
48
|
+
initial: 'idle',
|
|
49
|
+
context: {
|
|
50
|
+
user: undefined,
|
|
51
|
+
config: {},
|
|
52
|
+
services: defaultServices,
|
|
53
|
+
actorRef: undefined,
|
|
54
|
+
hasSetup: false,
|
|
55
|
+
},
|
|
56
|
+
predictableActionArguments: true,
|
|
57
|
+
states: {
|
|
58
|
+
// See: https://xstate.js.org/docs/guides/communication.html#invoking-promises
|
|
59
|
+
idle: {
|
|
60
|
+
invoke: {
|
|
61
|
+
src: 'handleGetCurrentUser',
|
|
62
|
+
onDone: { actions: 'setUser', target: 'authenticated' },
|
|
63
|
+
onError: { target: 'setup' },
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
setup: {
|
|
67
|
+
initial: 'initConfig',
|
|
68
|
+
states: {
|
|
69
|
+
initConfig,
|
|
70
|
+
getConfig: {
|
|
71
|
+
invoke: {
|
|
72
|
+
src: 'getAmplifyConfig',
|
|
73
|
+
onDone: {
|
|
74
|
+
actions: ['applyAmplifyConfig', 'setHasSetup'],
|
|
75
|
+
target: 'goToInitialState',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
goToInitialState: {
|
|
80
|
+
always: [
|
|
81
|
+
{
|
|
82
|
+
cond: 'isInitialStateSignUp',
|
|
83
|
+
target: '#authenticator.signUpActor',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
cond: 'isInitialStateResetPassword',
|
|
87
|
+
target: '#authenticator.forgotPasswordActor',
|
|
88
|
+
},
|
|
89
|
+
{ target: '#authenticator.signInActor' },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
getCurrentUser: {
|
|
95
|
+
invoke: {
|
|
96
|
+
src: 'handleGetCurrentUser',
|
|
97
|
+
onDone: {
|
|
98
|
+
actions: 'setUser',
|
|
99
|
+
target: '#authenticator.authenticated',
|
|
100
|
+
},
|
|
101
|
+
onError: { target: '#authenticator.setup' },
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
signInActor: {
|
|
105
|
+
initial: 'spawnActor',
|
|
106
|
+
states: {
|
|
107
|
+
spawnActor: {
|
|
108
|
+
always: { actions: 'spawnSignInActor', target: 'runActor' },
|
|
109
|
+
},
|
|
110
|
+
runActor: {
|
|
111
|
+
entry: 'clearActorDoneData',
|
|
112
|
+
exit: stopActor('signInActor'),
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
on: {
|
|
116
|
+
FORGOT_PASSWORD: 'forgotPasswordActor',
|
|
117
|
+
SIGN_IN: 'signInActor',
|
|
118
|
+
SIGN_UP: 'signUpActor',
|
|
119
|
+
'done.invoke.signInActor': [
|
|
120
|
+
{
|
|
121
|
+
cond: 'hasCompletedAttributeConfirmation',
|
|
122
|
+
target: '#authenticator.getCurrentUser',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
cond: 'isShouldConfirmUserAttributeStep',
|
|
126
|
+
actions: 'setActorDoneData',
|
|
127
|
+
target: '#authenticator.verifyUserAttributesActor',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
cond: 'isResetPasswordStep',
|
|
131
|
+
actions: 'setActorDoneData',
|
|
132
|
+
target: '#authenticator.forgotPasswordActor',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
cond: 'isConfirmSignUpStep',
|
|
136
|
+
actions: 'setActorDoneData',
|
|
137
|
+
target: '#authenticator.signUpActor',
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
signUpActor: {
|
|
143
|
+
initial: 'spawnActor',
|
|
144
|
+
states: {
|
|
145
|
+
spawnActor: {
|
|
146
|
+
always: { actions: 'spawnSignUpActor', target: 'runActor' },
|
|
147
|
+
},
|
|
148
|
+
runActor: {
|
|
149
|
+
entry: 'clearActorDoneData',
|
|
150
|
+
exit: stopActor('signUpActor'),
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
on: {
|
|
154
|
+
SIGN_IN: 'signInActor',
|
|
155
|
+
'done.invoke.signUpActor': [
|
|
156
|
+
{
|
|
157
|
+
cond: 'hasCompletedAttributeConfirmation',
|
|
158
|
+
target: '#authenticator.getCurrentUser',
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
cond: 'isConfirmUserAttributeStep',
|
|
162
|
+
target: '#authenticator.verifyUserAttributesActor',
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
actions: 'setActorDoneData',
|
|
166
|
+
target: '#authenticator.signInActor',
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
forgotPasswordActor: {
|
|
172
|
+
initial: 'spawnActor',
|
|
173
|
+
states: {
|
|
174
|
+
spawnActor: {
|
|
175
|
+
always: {
|
|
176
|
+
actions: 'spawnForgotPasswordActor',
|
|
177
|
+
target: 'runActor',
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
runActor: {
|
|
181
|
+
entry: 'clearActorDoneData',
|
|
182
|
+
exit: stopActor('forgotPasswordActor'),
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
on: {
|
|
186
|
+
SIGN_IN: 'signInActor',
|
|
187
|
+
'done.invoke.forgotPasswordActor': [
|
|
188
|
+
{ target: '#authenticator.signInActor' },
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
verifyUserAttributesActor: {
|
|
193
|
+
initial: 'spawnActor',
|
|
194
|
+
states: {
|
|
195
|
+
spawnActor: {
|
|
196
|
+
always: {
|
|
197
|
+
actions: 'spawnVerifyUserAttributesActor',
|
|
198
|
+
target: 'runActor',
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
runActor: {
|
|
202
|
+
entry: 'clearActorDoneData',
|
|
203
|
+
exit: stopActor('verifyUserAttributesActor'),
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
on: {
|
|
207
|
+
'done.invoke.verifyUserAttributesActor': [
|
|
208
|
+
{
|
|
209
|
+
actions: 'setActorDoneData',
|
|
210
|
+
target: '#authenticator.getCurrentUser',
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
authenticated: {
|
|
216
|
+
initial: 'idle',
|
|
217
|
+
states: {
|
|
218
|
+
idle: { on: { TOKEN_REFRESH: 'refreshUser' } },
|
|
219
|
+
refreshUser: {
|
|
220
|
+
invoke: {
|
|
221
|
+
src: '#authenticator.getCurrentUser',
|
|
222
|
+
onDone: { actions: 'setUser', target: 'idle' },
|
|
223
|
+
onError: { target: '#authenticator.signOut' },
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
on: { SIGN_OUT: 'signOut' },
|
|
228
|
+
},
|
|
229
|
+
signOut: {
|
|
230
|
+
initial: 'spawnActor',
|
|
231
|
+
states: {
|
|
232
|
+
spawnActor: {
|
|
233
|
+
always: {
|
|
234
|
+
actions: 'spawnSignOutActor',
|
|
235
|
+
target: 'runActor',
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
runActor: {
|
|
239
|
+
entry: 'clearActorDoneData',
|
|
240
|
+
exit: stopActor('signOutActor'),
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
on: {
|
|
244
|
+
'done.invoke.signOutActor': {
|
|
245
|
+
actions: 'clearUser',
|
|
246
|
+
target: 'setup.getConfig',
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
on: {
|
|
252
|
+
SIGN_IN_WITH_REDIRECT: { target: '#authenticator.getCurrentUser' },
|
|
253
|
+
CHANGE: { actions: 'forwardToActor' },
|
|
254
|
+
BLUR: { actions: 'forwardToActor' },
|
|
255
|
+
SUBMIT: { actions: 'forwardToActor' },
|
|
256
|
+
FEDERATED_SIGN_IN: { actions: 'forwardToActor' },
|
|
257
|
+
RESEND: { actions: 'forwardToActor' },
|
|
258
|
+
SIGN_IN: { actions: 'forwardToActor' },
|
|
259
|
+
SKIP: { actions: 'forwardToActor' },
|
|
260
|
+
},
|
|
261
|
+
}, {
|
|
262
|
+
actions: {
|
|
263
|
+
...ACTIONS,
|
|
264
|
+
forwardToActor: choose([
|
|
265
|
+
{ cond: 'hasActor', actions: forwardTo(({ actorRef }) => actorRef) },
|
|
266
|
+
]),
|
|
267
|
+
setActorDoneData: assign({
|
|
268
|
+
actorDoneData: (context, event) => ({
|
|
269
|
+
codeDeliveryDetails: event.data.codeDeliveryDetails,
|
|
270
|
+
missingAttributes: event.data.missingAttributes,
|
|
271
|
+
remoteError: event.data.remoteError,
|
|
272
|
+
username: event.data.username,
|
|
273
|
+
step: event.data.step,
|
|
274
|
+
totpSecretCode: event.data.totpSecretCode,
|
|
275
|
+
unverifiedUserAttributes: event.data.unverifiedUserAttributes,
|
|
276
|
+
}),
|
|
277
|
+
}),
|
|
278
|
+
applyAmplifyConfig: assign({
|
|
279
|
+
config(context, { data: cliConfig }) {
|
|
280
|
+
// Prefer explicitly configured settings over default CLI values\
|
|
281
|
+
const { loginMechanisms = cliConfig.loginMechanisms ?? [], signUpAttributes = cliConfig.signUpAttributes ?? [], socialProviders = cliConfig.socialProviders ?? [], initialState, formFields: _formFields, passwordSettings = cliConfig.passwordFormat ??
|
|
282
|
+
{}, } = context.config;
|
|
283
|
+
// By default, Cognito assumes `username`, so there isn't a different username attribute like `email`.
|
|
284
|
+
// We explicitly add it as a login mechanism to be consistent with Admin UI's language.
|
|
285
|
+
if (loginMechanisms.length === 0) {
|
|
286
|
+
loginMechanisms.push('username');
|
|
287
|
+
}
|
|
288
|
+
const formFields = convertFormFields(_formFields) ?? {};
|
|
289
|
+
return {
|
|
290
|
+
formFields,
|
|
291
|
+
initialState,
|
|
292
|
+
loginMechanisms,
|
|
293
|
+
passwordSettings,
|
|
294
|
+
signUpAttributes,
|
|
295
|
+
socialProviders,
|
|
296
|
+
};
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
spawnSignInActor: assign({
|
|
300
|
+
actorRef: (context, _) => {
|
|
301
|
+
const { services } = context;
|
|
302
|
+
const actor = signInActor({ services }).withContext(getActorContext(context, 'SIGN_IN'));
|
|
303
|
+
return spawn(actor, { name: 'signInActor' });
|
|
304
|
+
},
|
|
305
|
+
}),
|
|
306
|
+
spawnSignUpActor: assign({
|
|
307
|
+
actorRef: (context, _) => {
|
|
308
|
+
const { services } = context;
|
|
309
|
+
const actor = signUpActor({ services }).withContext(getActorContext(context, 'SIGN_UP'));
|
|
310
|
+
return spawn(actor, { name: 'signUpActor' });
|
|
311
|
+
},
|
|
312
|
+
}),
|
|
313
|
+
spawnForgotPasswordActor: assign({
|
|
314
|
+
actorRef: (context, _) => {
|
|
315
|
+
const { services } = context;
|
|
316
|
+
const actor = forgotPasswordActor({ services }).withContext(getActorContext(context, 'FORGOT_PASSWORD'));
|
|
317
|
+
return spawn(actor, { name: 'forgotPasswordActor' });
|
|
318
|
+
},
|
|
319
|
+
}),
|
|
320
|
+
spawnVerifyUserAttributesActor: assign({
|
|
321
|
+
actorRef: (context) => {
|
|
322
|
+
const actor = verifyUserAttributesActor().withContext(getActorContext(context));
|
|
323
|
+
return spawn(actor, { name: 'verifyUserAttributesActor' });
|
|
324
|
+
},
|
|
325
|
+
}),
|
|
326
|
+
spawnSignOutActor: assign({
|
|
327
|
+
actorRef: (context) => {
|
|
328
|
+
const actor = signOutActor().withContext({ user: context?.user });
|
|
329
|
+
return spawn(actor, { name: 'signOutActor' });
|
|
330
|
+
},
|
|
331
|
+
}),
|
|
332
|
+
configure: assign((_, event) => {
|
|
333
|
+
const { services: customServices, ...config } = !isEmptyObject(overrideConfigServices)
|
|
334
|
+
? overrideConfigServices
|
|
335
|
+
: event.data;
|
|
336
|
+
return {
|
|
337
|
+
services: { ...defaultServices, ...customServices },
|
|
338
|
+
config,
|
|
339
|
+
};
|
|
340
|
+
}),
|
|
341
|
+
setHasSetup: assign({ hasSetup: true }),
|
|
342
|
+
},
|
|
343
|
+
guards: {
|
|
344
|
+
...GUARDS,
|
|
345
|
+
hasActor: ({ actorRef }) => !!actorRef,
|
|
346
|
+
isInitialStateSignUp: ({ config }) => config.initialState === 'signUp',
|
|
347
|
+
isInitialStateResetPassword: ({ config }) => config.initialState === 'forgotPassword',
|
|
348
|
+
shouldSetup: ({ hasSetup }) => !hasSetup,
|
|
349
|
+
},
|
|
350
|
+
services: {
|
|
351
|
+
getAmplifyConfig: ({ services }) => services.getAmplifyConfig(),
|
|
352
|
+
handleGetCurrentUser: ({ services }) => services.getCurrentUser(),
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
function convertFormFields(formFields) {
|
|
357
|
+
if (formFields) {
|
|
358
|
+
Object.keys(formFields).forEach((component) => {
|
|
359
|
+
Object.keys(formFields[component]).forEach((inputName) => {
|
|
360
|
+
let ff = formFields[component][inputName];
|
|
361
|
+
ff.required = ff.isRequired;
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
return formFields;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export { createAuthenticatorMachine };
|