Skip to content

Commit a7208ab

Browse files
authored
fix: update user attributes mapping to have all the attributes (#1519)
1 parent 52493d3 commit a7208ab

File tree

6 files changed

+64
-95
lines changed

6 files changed

+64
-95
lines changed

.changeset/ninety-spiders-end.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/auth-construct': patch
3+
---
4+
5+
update user attributes mapping to have all the attributes

.eslint_dictionary.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,6 @@
175175
"wildcards",
176176
"workspace",
177177
"yaml",
178-
"yargs"
178+
"yargs",
179+
"zoneinfo"
179180
]

package-lock.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/auth-construct/src/construct.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,17 +819,31 @@ void describe('Auth construct', () => {
819819
email: true,
820820
},
821821
userAttributes: {
822-
phoneNumber: { required: true, mutable: true },
823-
familyName: { required: false, mutable: true },
824-
address: { required: true, mutable: true },
822+
address: { required: true },
823+
birthdate: { required: true },
824+
gender: { required: true },
825+
locale: { required: true },
826+
middleName: { required: true },
827+
nickname: { required: true },
828+
phoneNumber: { required: true },
829+
profilePicture: { required: true },
830+
fullname: { required: true },
831+
givenName: { required: true },
832+
familyName: { required: true },
833+
lastUpdateTime: { required: true },
834+
preferredUsername: { required: true },
835+
profilePage: { required: true },
836+
timezone: { required: true },
837+
website: { required: true },
838+
email: { required: true, mutable: false },
825839
},
826840
outputStorageStrategy: stubBackendOutputStorageStrategy,
827841
});
828842
const { payload } = storeOutputMock.mock.calls[0].arguments[1];
829843

830844
assert.equal(
831845
payload.signupAttributes,
832-
'["email","phone_number","address"]'
846+
'["email","phone_number","address","birthdate","gender","locale","middle_name","nickname","picture","name","given_name","family_name","updated_at","preferred_username","profile","zoneinfo","website"]'
833847
);
834848
});
835849

packages/auth-construct/src/construct.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
OAuthScope,
1515
OidcAttributeRequestMethod,
1616
ProviderAttribute,
17+
StandardAttributes,
1718
UserPool,
1819
UserPoolClient,
1920
UserPoolIdentityProviderAmazon,
@@ -894,16 +895,10 @@ export class AmplifyAuth
894895
this.computedUserPoolProps.standardAttributes
895896
).reduce((acc: string[], [attributeName, attribute]) => {
896897
if (attribute?.required) {
897-
const treatedAttributeName = coreAttributeNameMap.find(
898-
({ standardAttributeName }) =>
899-
standardAttributeName === attributeName
900-
);
901-
898+
const treatedAttributeName =
899+
coreAttributeNameMap[attributeName as keyof StandardAttributes];
902900
if (treatedAttributeName) {
903-
return [
904-
...acc,
905-
treatedAttributeName.userpoolAttributeName.toLowerCase(),
906-
];
901+
return [...acc, treatedAttributeName];
907902
}
908903
}
909904
return acc;
Lines changed: 19 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,24 @@
11
import { StandardAttributes } from 'aws-cdk-lib/aws-cognito';
22

33
// refer: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html
4-
const coreAttributeNameMap: {
5-
standardAttributeName: keyof StandardAttributes;
6-
userpoolAttributeName: string;
7-
}[] = [
8-
{
9-
standardAttributeName: 'address',
10-
userpoolAttributeName: 'address',
11-
},
12-
{
13-
standardAttributeName: 'birthdate',
14-
userpoolAttributeName: 'birthdate',
15-
},
16-
{
17-
standardAttributeName: 'email',
18-
userpoolAttributeName: 'email',
19-
},
20-
{
21-
standardAttributeName: 'familyName',
22-
userpoolAttributeName: 'family_name',
23-
},
24-
{
25-
standardAttributeName: 'gender',
26-
userpoolAttributeName: 'gender',
27-
},
28-
{
29-
standardAttributeName: 'givenName',
30-
userpoolAttributeName: 'given_name',
31-
},
32-
{
33-
standardAttributeName: 'locale',
34-
userpoolAttributeName: 'locale',
35-
},
36-
{
37-
standardAttributeName: 'middleName',
38-
userpoolAttributeName: 'middle_name',
39-
},
40-
{
41-
standardAttributeName: 'nickname',
42-
userpoolAttributeName: 'nickname',
43-
},
44-
{
45-
standardAttributeName: 'phoneNumber',
46-
userpoolAttributeName: 'phone_number',
47-
},
48-
{
49-
standardAttributeName: 'profilePicture',
50-
userpoolAttributeName: 'picture',
51-
},
52-
{
53-
standardAttributeName: 'preferredUsername',
54-
userpoolAttributeName: 'preferred_username',
55-
},
56-
{
57-
standardAttributeName: 'profilePage',
58-
userpoolAttributeName: 'profile',
59-
},
60-
{
61-
standardAttributeName: 'lastUpdateTime',
62-
userpoolAttributeName: 'updated_at',
63-
},
64-
{
65-
standardAttributeName: 'website',
66-
userpoolAttributeName: 'website',
67-
},
68-
];
4+
const coreAttributeNameMap: Record<keyof StandardAttributes, string> = {
5+
address: 'address',
6+
birthdate: 'birthdate',
7+
email: 'email',
8+
familyName: 'family_name',
9+
gender: 'gender',
10+
givenName: 'given_name',
11+
locale: 'locale',
12+
middleName: 'middle_name',
13+
fullname: 'name',
14+
nickname: 'nickname',
15+
phoneNumber: 'phone_number',
16+
profilePicture: 'picture',
17+
preferredUsername: 'preferred_username',
18+
profilePage: 'profile',
19+
timezone: 'zoneinfo',
20+
lastUpdateTime: 'updated_at',
21+
website: 'website',
22+
};
6923

7024
export { coreAttributeNameMap };

0 commit comments

Comments
 (0)