@aws-amplify/ui-react-core 2.1.5 → 2.1.6
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/Authenticator/hooks/useAuthenticator/useAuthenticator.js +6 -2
- package/dist/esm/Authenticator/hooks/useAuthenticator/utils.js +8 -2
- package/dist/index.js +11 -1
- package/dist/types/Authenticator/hooks/useAuthenticator/types.d.ts +5 -0
- package/dist/types/Authenticator/hooks/useAuthenticator/utils.d.ts +4 -0
- package/package.json +2 -2
|
@@ -5,7 +5,7 @@ import { getServiceFacade } from '@aws-amplify/ui';
|
|
|
5
5
|
import 'react/jsx-runtime';
|
|
6
6
|
import { AuthenticatorContext } from '../../context/AuthenticatorContext.js';
|
|
7
7
|
import { USE_AUTHENTICATOR_ERROR } from './constants.js';
|
|
8
|
-
import { getMachineFields, getTotpSecretCodeCallback, getComparator, defaultComparator } from './utils.js';
|
|
8
|
+
import { getQRFields, getMachineFields, getTotpSecretCodeCallback, getComparator, defaultComparator } from './utils.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/authenticator/headless#useauthenticator-hook)
|
|
@@ -24,13 +24,17 @@ function useAuthenticator(selector) {
|
|
|
24
24
|
// do not memoize output. `service.getSnapshot` reference remains stable preventing
|
|
25
25
|
// `fields` from updating with current form state on value changes
|
|
26
26
|
const serviceSnapshot = service.getSnapshot();
|
|
27
|
+
// legacy `QRFields` values only used for SetupTOTP page to retrieve issuer information, will be removed in future
|
|
28
|
+
const QRFields = useMemo(() => getQRFields(serviceSnapshot), [serviceSnapshot]);
|
|
27
29
|
// legacy `formFields` values required until form state is removed from state machine
|
|
28
30
|
const fields = useMemo(() => getMachineFields(route, serviceSnapshot, unverifiedContactMethods), [route, serviceSnapshot, unverifiedContactMethods]);
|
|
29
31
|
return Object.assign(Object.assign({}, rest), { getTotpSecretCode: getTotpSecretCodeCallback(user), route,
|
|
30
32
|
unverifiedContactMethods,
|
|
31
33
|
user,
|
|
32
34
|
/** @deprecated For internal use only */
|
|
33
|
-
fields
|
|
35
|
+
fields,
|
|
36
|
+
/** @deprecated For internal use only */
|
|
37
|
+
QRFields });
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
export { useAuthenticator as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
2
|
import { Auth } from 'aws-amplify';
|
|
3
|
-
import { getSortedFormFields } from '@aws-amplify/ui';
|
|
3
|
+
import { getActorContext, getSortedFormFields } from '@aws-amplify/ui';
|
|
4
4
|
import isString from 'lodash/isString';
|
|
5
5
|
import { areEmptyArrays, areEmptyObjects } from '../../../utils/index.js';
|
|
6
6
|
import { isComponentRouteKey } from '../utils.js';
|
|
@@ -29,6 +29,12 @@ const getComparator = (selector) => (currentFacade, nextFacade) => {
|
|
|
29
29
|
// Shallow compare the array values
|
|
30
30
|
return areSelectorDepsEqual(currentSelectorDeps, nextSelectorDeps);
|
|
31
31
|
};
|
|
32
|
+
const getQRFields = (state) => {
|
|
33
|
+
var _a, _b, _c;
|
|
34
|
+
const fields = getActorContext(state);
|
|
35
|
+
const QR = (_c = (_b = (_a = fields === null || fields === void 0 ? void 0 : fields.formFields) === null || _a === void 0 ? void 0 : _a.setupTOTP) === null || _b === void 0 ? void 0 : _b.QR) !== null && _c !== void 0 ? _c : {};
|
|
36
|
+
return Object.assign({}, QR);
|
|
37
|
+
};
|
|
32
38
|
const getTotpSecretCodeCallback = (user) => function getTotpSecretCode() {
|
|
33
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
40
|
return yield Auth.setupTOTP(user);
|
|
@@ -58,4 +64,4 @@ const getMachineFields = (route, state, unverifiedContactMethods) => {
|
|
|
58
64
|
return [];
|
|
59
65
|
};
|
|
60
66
|
|
|
61
|
-
export { areSelectorDepsEqual, defaultComparator, getComparator, getMachineFields, getTotpSecretCodeCallback };
|
|
67
|
+
export { areSelectorDepsEqual, defaultComparator, getComparator, getMachineFields, getQRFields, getTotpSecretCodeCallback };
|
package/dist/index.js
CHANGED
|
@@ -172,6 +172,12 @@ const getComparator = (selector) => (currentFacade, nextFacade) => {
|
|
|
172
172
|
// Shallow compare the array values
|
|
173
173
|
return areSelectorDepsEqual(currentSelectorDeps, nextSelectorDeps);
|
|
174
174
|
};
|
|
175
|
+
const getQRFields = (state) => {
|
|
176
|
+
var _a, _b, _c;
|
|
177
|
+
const fields = ui.getActorContext(state);
|
|
178
|
+
const QR = (_c = (_b = (_a = fields === null || fields === void 0 ? void 0 : fields.formFields) === null || _a === void 0 ? void 0 : _a.setupTOTP) === null || _b === void 0 ? void 0 : _b.QR) !== null && _c !== void 0 ? _c : {};
|
|
179
|
+
return Object.assign({}, QR);
|
|
180
|
+
};
|
|
175
181
|
const getTotpSecretCodeCallback = (user) => function getTotpSecretCode() {
|
|
176
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
177
183
|
return yield awsAmplify.Auth.setupTOTP(user);
|
|
@@ -218,13 +224,17 @@ function useAuthenticator(selector) {
|
|
|
218
224
|
// do not memoize output. `service.getSnapshot` reference remains stable preventing
|
|
219
225
|
// `fields` from updating with current form state on value changes
|
|
220
226
|
const serviceSnapshot = service.getSnapshot();
|
|
227
|
+
// legacy `QRFields` values only used for SetupTOTP page to retrieve issuer information, will be removed in future
|
|
228
|
+
const QRFields = React.useMemo(() => getQRFields(serviceSnapshot), [serviceSnapshot]);
|
|
221
229
|
// legacy `formFields` values required until form state is removed from state machine
|
|
222
230
|
const fields = React.useMemo(() => getMachineFields(route, serviceSnapshot, unverifiedContactMethods), [route, serviceSnapshot, unverifiedContactMethods]);
|
|
223
231
|
return Object.assign(Object.assign({}, rest), { getTotpSecretCode: getTotpSecretCodeCallback(user), route,
|
|
224
232
|
unverifiedContactMethods,
|
|
225
233
|
user,
|
|
226
234
|
/** @deprecated For internal use only */
|
|
227
|
-
fields
|
|
235
|
+
fields,
|
|
236
|
+
/** @deprecated For internal use only */
|
|
237
|
+
QRFields });
|
|
228
238
|
}
|
|
229
239
|
|
|
230
240
|
/**
|
|
@@ -17,6 +17,11 @@ export declare type UseAuthenticatorSelector = (context: AuthenticatorMachineCon
|
|
|
17
17
|
export interface UseAuthenticator extends AuthenticatorServiceFacade {
|
|
18
18
|
getTotpSecretCode: () => Promise<string>;
|
|
19
19
|
/** @deprecated For internal use only */
|
|
20
|
+
QRFields: {
|
|
21
|
+
totpIssuer?: string;
|
|
22
|
+
totpUsername?: string;
|
|
23
|
+
};
|
|
24
|
+
/** @deprecated For internal use only */
|
|
20
25
|
fields: AuthenticatorLegacyFields;
|
|
21
26
|
}
|
|
22
27
|
export declare type Comparator = (currentMachineContext: AuthenticatorMachineContext, nextMachineContext: AuthenticatorMachineContext) => boolean;
|
|
@@ -8,6 +8,10 @@ export declare const defaultComparator: () => false;
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function areSelectorDepsEqual<T>(currentDeps: T[], nextDeps: T[]): boolean;
|
|
10
10
|
export declare const getComparator: (selector: UseAuthenticatorSelector) => Comparator;
|
|
11
|
+
export declare const getQRFields: (state: AuthMachineState) => {
|
|
12
|
+
totpIssuer?: string;
|
|
13
|
+
totpUsername?: string;
|
|
14
|
+
};
|
|
11
15
|
export declare const getTotpSecretCodeCallback: (user: AmplifyUser) => () => Promise<string>;
|
|
12
16
|
/**
|
|
13
17
|
* Retrieves default and custom (RWA only, to be updated) form field values from state machine
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"react-native": "dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"test:watch": "yarn test --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@aws-amplify/ui": "5.4.
|
|
31
|
+
"@aws-amplify/ui": "5.4.1",
|
|
32
32
|
"@xstate/react": "3.0.1",
|
|
33
33
|
"lodash": "4.17.21",
|
|
34
34
|
"xstate": "^4.33.6"
|