@aws-amplify/ui 6.0.5 → 6.0.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/helpers/authenticator/defaultAuthHubHandler.mjs +7 -11
- package/dist/esm/machines/authenticator/defaultServices.mjs +12 -3
- package/dist/index.js +19 -14
- package/dist/types/helpers/authenticator/defaultAuthHubHandler.d.ts +3 -3
- package/dist/types/helpers/authenticator/types.d.ts +1 -1
- package/dist/types/machines/authenticator/defaultServices.d.ts +11 -10
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import { isFunction } from '../../utils/utils.mjs';
|
|
|
7
7
|
* Handles Amplify JS Auth hub events, by forwarding hub events as appropriate
|
|
8
8
|
* xstate events.
|
|
9
9
|
*/
|
|
10
|
-
const defaultAuthHubHandler =
|
|
10
|
+
const defaultAuthHubHandler = ({ payload }, service, options) => {
|
|
11
11
|
const { event } = payload;
|
|
12
12
|
const { send } = service;
|
|
13
13
|
const { onSignIn, onSignOut } = options ?? {};
|
|
@@ -32,21 +32,17 @@ const defaultAuthHubHandler = async ({ payload }, service, options) => {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
const getHubEventHandler = (service, handler) => (data) => {
|
|
36
|
-
handler(data, service);
|
|
37
|
-
};
|
|
38
35
|
/**
|
|
39
36
|
* Listens to external auth Hub events and sends corresponding event to
|
|
40
|
-
* the `
|
|
41
|
-
*
|
|
42
|
-
* @param send - `send` function associated with the `authService` of interest
|
|
37
|
+
* the `service.send` of interest
|
|
43
38
|
*
|
|
39
|
+
* @param service - contains state machine `send` function
|
|
40
|
+
* @param handler - auth event handler
|
|
44
41
|
* @returns function that unsubscribes to the hub evenmt
|
|
45
42
|
*/
|
|
46
|
-
const listenToAuthHub = (service,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return Hub.listen('auth', getHubEventHandler(service, handler), 'authenticator-hub-handler');
|
|
43
|
+
const listenToAuthHub = (service, handler = defaultAuthHubHandler) => {
|
|
44
|
+
const eventHandler = (data) => handler(data, service);
|
|
45
|
+
return Hub.listen('auth', eventHandler, 'authenticator-hub-handler');
|
|
50
46
|
};
|
|
51
47
|
|
|
52
48
|
export { defaultAuthHubHandler, listenToAuthHub };
|
|
@@ -10,6 +10,17 @@ import '../../helpers/accountSettings/utils.mjs';
|
|
|
10
10
|
|
|
11
11
|
// Cognito does not allow a password length less then 8 characters
|
|
12
12
|
const DEFAULT_COGNITO_PASSWORD_MIN_LENGTH = 8;
|
|
13
|
+
const isInvalidUserAtributes = (userAttributes) => Array.isArray(userAttributes);
|
|
14
|
+
const parseUserAttributes = (userAttributes) => {
|
|
15
|
+
if (!userAttributes) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
// `aws-amplify` versions <= 6.0.5 return an array of `userAttributes` rather than an object
|
|
19
|
+
if (isInvalidUserAtributes(userAttributes)) {
|
|
20
|
+
return Object.entries(userAttributes).map(([_, value]) => Object.keys(value)[0]);
|
|
21
|
+
}
|
|
22
|
+
return Object.keys(userAttributes);
|
|
23
|
+
};
|
|
13
24
|
const defaultServices = {
|
|
14
25
|
async getAmplifyConfig() {
|
|
15
26
|
const result = Amplify.getConfig();
|
|
@@ -25,9 +36,7 @@ const defaultServices = {
|
|
|
25
36
|
: keyValueArray[0];
|
|
26
37
|
})
|
|
27
38
|
: undefined;
|
|
28
|
-
const parsedSignupAttributes = userAttributes
|
|
29
|
-
? Object.entries(userAttributes).map(([_key, value]) => Object.keys(value)[0])
|
|
30
|
-
: undefined;
|
|
39
|
+
const parsedSignupAttributes = parseUserAttributes(userAttributes);
|
|
31
40
|
const parsedSocialProviders = loginWith?.oauth?.providers
|
|
32
41
|
? loginWith.oauth.providers?.map((provider) => provider.toString().toLowerCase())
|
|
33
42
|
: undefined;
|
package/dist/index.js
CHANGED
|
@@ -408,7 +408,7 @@ const classNames = (...args) => {
|
|
|
408
408
|
* Handles Amplify JS Auth hub events, by forwarding hub events as appropriate
|
|
409
409
|
* xstate events.
|
|
410
410
|
*/
|
|
411
|
-
const defaultAuthHubHandler =
|
|
411
|
+
const defaultAuthHubHandler = ({ payload }, service, options) => {
|
|
412
412
|
const { event } = payload;
|
|
413
413
|
const { send } = service;
|
|
414
414
|
const { onSignIn, onSignOut } = options ?? {};
|
|
@@ -433,21 +433,17 @@ const defaultAuthHubHandler = async ({ payload }, service, options) => {
|
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
};
|
|
436
|
-
const getHubEventHandler = (service, handler) => (data) => {
|
|
437
|
-
handler(data, service);
|
|
438
|
-
};
|
|
439
436
|
/**
|
|
440
437
|
* Listens to external auth Hub events and sends corresponding event to
|
|
441
|
-
* the `
|
|
442
|
-
*
|
|
443
|
-
* @param send - `send` function associated with the `authService` of interest
|
|
438
|
+
* the `service.send` of interest
|
|
444
439
|
*
|
|
440
|
+
* @param service - contains state machine `send` function
|
|
441
|
+
* @param handler - auth event handler
|
|
445
442
|
* @returns function that unsubscribes to the hub evenmt
|
|
446
443
|
*/
|
|
447
|
-
const listenToAuthHub = (service,
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
return utils$1.Hub.listen('auth', getHubEventHandler(service, handler), 'authenticator-hub-handler');
|
|
444
|
+
const listenToAuthHub = (service, handler = defaultAuthHubHandler) => {
|
|
445
|
+
const eventHandler = (data) => handler(data, service);
|
|
446
|
+
return utils$1.Hub.listen('auth', eventHandler, 'authenticator-hub-handler');
|
|
451
447
|
};
|
|
452
448
|
|
|
453
449
|
const countryDialCodes = [
|
|
@@ -3611,6 +3607,17 @@ const runValidators = async (formData, touchData, passwordSettings, validators)
|
|
|
3611
3607
|
|
|
3612
3608
|
// Cognito does not allow a password length less then 8 characters
|
|
3613
3609
|
const DEFAULT_COGNITO_PASSWORD_MIN_LENGTH = 8;
|
|
3610
|
+
const isInvalidUserAtributes = (userAttributes) => Array.isArray(userAttributes);
|
|
3611
|
+
const parseUserAttributes = (userAttributes) => {
|
|
3612
|
+
if (!userAttributes) {
|
|
3613
|
+
return undefined;
|
|
3614
|
+
}
|
|
3615
|
+
// `aws-amplify` versions <= 6.0.5 return an array of `userAttributes` rather than an object
|
|
3616
|
+
if (isInvalidUserAtributes(userAttributes)) {
|
|
3617
|
+
return Object.entries(userAttributes).map(([_, value]) => Object.keys(value)[0]);
|
|
3618
|
+
}
|
|
3619
|
+
return Object.keys(userAttributes);
|
|
3620
|
+
};
|
|
3614
3621
|
const defaultServices = {
|
|
3615
3622
|
async getAmplifyConfig() {
|
|
3616
3623
|
const result = awsAmplify.Amplify.getConfig();
|
|
@@ -3626,9 +3633,7 @@ const defaultServices = {
|
|
|
3626
3633
|
: keyValueArray[0];
|
|
3627
3634
|
})
|
|
3628
3635
|
: undefined;
|
|
3629
|
-
const parsedSignupAttributes = userAttributes
|
|
3630
|
-
? Object.entries(userAttributes).map(([_key, value]) => Object.keys(value)[0])
|
|
3631
|
-
: undefined;
|
|
3636
|
+
const parsedSignupAttributes = parseUserAttributes(userAttributes);
|
|
3632
3637
|
const parsedSocialProviders = loginWith?.oauth?.providers
|
|
3633
3638
|
? loginWith.oauth.providers?.map((provider) => provider.toString().toLowerCase())
|
|
3634
3639
|
: undefined;
|
|
@@ -6,10 +6,10 @@ import { AuthInterpreter, AuthMachineHubHandler } from './types';
|
|
|
6
6
|
export declare const defaultAuthHubHandler: AuthMachineHubHandler;
|
|
7
7
|
/**
|
|
8
8
|
* Listens to external auth Hub events and sends corresponding event to
|
|
9
|
-
* the `
|
|
10
|
-
*
|
|
11
|
-
* @param send - `send` function associated with the `authService` of interest
|
|
9
|
+
* the `service.send` of interest
|
|
12
10
|
*
|
|
11
|
+
* @param service - contains state machine `send` function
|
|
12
|
+
* @param handler - auth event handler
|
|
13
13
|
* @returns function that unsubscribes to the hub evenmt
|
|
14
14
|
*/
|
|
15
15
|
export declare const listenToAuthHub: (service: AuthInterpreter, handler?: AuthMachineHubHandler) => import("@aws-amplify/core/dist/esm/Hub/types").StopListenerCallback;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { UserAttributeKey } from 'aws-amplify/auth';
|
|
1
2
|
import { confirmResetPassword, confirmSignIn, confirmSignUp, resetPassword, signIn, signUp } from 'aws-amplify/auth';
|
|
2
|
-
import { AuthFormData, AuthTouchData, PasswordSettings,
|
|
3
|
+
import { AuthFormData, AuthTouchData, PasswordSettings, SocialProvider, ValidatorResult } from '../../types';
|
|
3
4
|
export declare const defaultServices: {
|
|
4
5
|
getAmplifyConfig(): Promise<{
|
|
5
6
|
loginMechanisms: ("email" | "phone_number" | "username")[];
|
|
6
|
-
signUpAttributes:
|
|
7
|
+
signUpAttributes: UserAttributeKey[];
|
|
7
8
|
socialProviders: SocialProvider[];
|
|
8
9
|
identityPoolId: string;
|
|
9
10
|
allowGuestAccess?: boolean;
|
|
@@ -17,7 +18,7 @@ export declare const defaultServices: {
|
|
|
17
18
|
passwordFormat?: never;
|
|
18
19
|
} | {
|
|
19
20
|
loginMechanisms: ("email" | "phone_number" | "username")[];
|
|
20
|
-
signUpAttributes:
|
|
21
|
+
signUpAttributes: UserAttributeKey[];
|
|
21
22
|
socialProviders: SocialProvider[];
|
|
22
23
|
userPoolClientId: string;
|
|
23
24
|
userPoolId: string;
|
|
@@ -48,7 +49,7 @@ export declare const defaultServices: {
|
|
|
48
49
|
allowGuestAccess?: never;
|
|
49
50
|
} | {
|
|
50
51
|
loginMechanisms: ("email" | "phone_number" | "username")[];
|
|
51
|
-
signUpAttributes:
|
|
52
|
+
signUpAttributes: UserAttributeKey[];
|
|
52
53
|
socialProviders: SocialProvider[];
|
|
53
54
|
identityPoolId: never;
|
|
54
55
|
allowGuestAccess?: never;
|
|
@@ -62,7 +63,7 @@ export declare const defaultServices: {
|
|
|
62
63
|
passwordFormat?: never;
|
|
63
64
|
} | {
|
|
64
65
|
loginMechanisms: ("email" | "phone_number" | "username")[];
|
|
65
|
-
signUpAttributes:
|
|
66
|
+
signUpAttributes: UserAttributeKey[];
|
|
66
67
|
socialProviders: SocialProvider[];
|
|
67
68
|
identityPoolId: string;
|
|
68
69
|
allowGuestAccess?: boolean;
|
|
@@ -76,7 +77,7 @@ export declare const defaultServices: {
|
|
|
76
77
|
passwordFormat?: never;
|
|
77
78
|
} | {
|
|
78
79
|
loginMechanisms: ("email" | "phone_number" | "username")[];
|
|
79
|
-
signUpAttributes:
|
|
80
|
+
signUpAttributes: UserAttributeKey[];
|
|
80
81
|
socialProviders: SocialProvider[];
|
|
81
82
|
userPoolClientId: never;
|
|
82
83
|
userPoolId: never;
|
|
@@ -90,7 +91,7 @@ export declare const defaultServices: {
|
|
|
90
91
|
allowGuestAccess?: never;
|
|
91
92
|
} | {
|
|
92
93
|
loginMechanisms: ("email" | "phone_number" | "username")[];
|
|
93
|
-
signUpAttributes:
|
|
94
|
+
signUpAttributes: UserAttributeKey[];
|
|
94
95
|
socialProviders: SocialProvider[];
|
|
95
96
|
userPoolClientId: string;
|
|
96
97
|
userPoolId: string;
|
|
@@ -121,7 +122,7 @@ export declare const defaultServices: {
|
|
|
121
122
|
allowGuestAccess?: never;
|
|
122
123
|
} | {
|
|
123
124
|
loginMechanisms: ("email" | "phone_number" | "username")[];
|
|
124
|
-
signUpAttributes:
|
|
125
|
+
signUpAttributes: UserAttributeKey[];
|
|
125
126
|
socialProviders: SocialProvider[];
|
|
126
127
|
userPoolClientId: never;
|
|
127
128
|
userPoolId: never;
|
|
@@ -135,7 +136,7 @@ export declare const defaultServices: {
|
|
|
135
136
|
allowGuestAccess?: boolean;
|
|
136
137
|
} | {
|
|
137
138
|
loginMechanisms: ("email" | "phone_number" | "username")[];
|
|
138
|
-
signUpAttributes:
|
|
139
|
+
signUpAttributes: UserAttributeKey[];
|
|
139
140
|
socialProviders: SocialProvider[];
|
|
140
141
|
userPoolClientId: string;
|
|
141
142
|
userPoolId: string;
|
|
@@ -166,7 +167,7 @@ export declare const defaultServices: {
|
|
|
166
167
|
allowGuestAccess?: never;
|
|
167
168
|
} | {
|
|
168
169
|
loginMechanisms: ("email" | "phone_number" | "username")[];
|
|
169
|
-
signUpAttributes:
|
|
170
|
+
signUpAttributes: UserAttributeKey[];
|
|
170
171
|
socialProviders: SocialProvider[];
|
|
171
172
|
userPoolClientId: string;
|
|
172
173
|
userPoolId: string;
|