You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add docs for auth custom attribute support (#7846)
* add docs for auth custom attribute support
* Update src/pages/[platform]/build-a-backend/auth/concepts/user-attributes/index.mdx
* correct heading order
* fix broken links
* add mobile platform to concepts page for user attributes
Copy file name to clipboardExpand all lines: src/pages/[platform]/build-a-backend/auth/concepts/user-attributes/index.mdx
+62-11Lines changed: 62 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,14 @@ export const meta = {
4
4
title: 'User attributes',
5
5
description: 'Learn more about what Amplify Auth provisions and supports',
6
6
platforms: [
7
-
//'android',
7
+
'android',
8
8
'angular',
9
-
//'flutter',
9
+
'flutter',
10
10
'javascript',
11
11
'nextjs',
12
12
'react',
13
-
//'react-native',
14
-
//'swift',
13
+
'react-native',
14
+
'swift',
15
15
'vue'
16
16
]
17
17
};
@@ -28,10 +28,16 @@ export function getStaticProps() {
28
28
};
29
29
}
30
30
31
-
Amplify Auth stores user profile information in user attributes. When the default method for user sign-in, Amplify Auth will automatically configure an `email` or `phone_number` attribute that is required for sign-in.
31
+
Amplify Auth stores user profile information in user attributes. When the default method for user sign-in, Amplify Auth will automatically configure an `email` or `phoneNumber` attribute that is required for sign-in.
32
32
33
33
{/* what standard attributes are */}
34
-
To extend a user profile beyond the default `email` or `phone_number` attribute that is automatically configured when specified in your auth resource's `loginWith` property, you can configure attributes with the `userAttributes` property:
34
+
To extend a user profile beyond the default `email` or `phoneNumber` attribute that is automatically configured when specified in your auth resource's `loginWith` property, you can configure attributes with the `userAttributes` property:
35
+
36
+
<Calloutwarning>
37
+
38
+
**Warning**: After you create your auth resource, you cannot switch an attribute between required and not required.
User attributes are defined as [Cognito Standard Attributes](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#cognito-user-pools-standard-attributes). Attributes can be configured to be _required_ for user sign-up in addition to whether the values are _mutable_. When configuring your resource to allow your users to login with `email`, an email must be specified for user sign-up and cannot be changed later. However additional attributes can be configured to be optional, and mutable after sign-up.
57
65
58
-
<Calloutwarning>
66
+
## Custom attributes
59
67
60
-
**Warning**: After you create your auth resource, you cannot switch an attribute between required and not required.
68
+
In addition to the provided standard attributes, you can configure [Custom Attributes](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-custom-attributes). These are attributes that are typically unique to your use case, such as a tenant ID or a user's display name. Custom attributes are identified by the `custom:` prefix:
61
69
62
-
</Callout>
70
+
```ts title="amplify/auth/resource.ts"
71
+
import { defineAuth } from"@aws-amplify/backend"
72
+
73
+
exportconst auth =defineAuth({
74
+
loginWith: {
75
+
// this configures a required "email" attribute
76
+
email: true,
77
+
},
78
+
userAttributes: {
79
+
// highlight-start
80
+
"custom:display_name": {
81
+
dataType: "String",
82
+
mutable: true,
83
+
maxLen: 16,
84
+
minLen: 1,
85
+
},
86
+
"custom:favorite_number": {
87
+
dataType: "Number",
88
+
mutable: true,
89
+
min: 1,
90
+
max: 100,
91
+
},
92
+
"custom:is_beta_user": {
93
+
dataType: "Boolean",
94
+
mutable: true,
95
+
},
96
+
"custom:started_free_trial": {
97
+
dataType: "DateTime",
98
+
mutable: true,
99
+
},
100
+
// highlight-end
101
+
},
102
+
})
103
+
```
104
+
105
+
Unlike standard attributes, custom attributes cannot natively be required for sign-up, however can be codified to require some value by [validating user attributes upon sign-up with a pre sign-up trigger](/[platform]/build-a-backend/functions/examples/user-attribute-validation/).
106
+
107
+
Custom attributes can also be configured with specific data types. The following data types are supported:
108
+
109
+
-`String`
110
+
-`Number`
111
+
-`Boolean`
112
+
-`DateTime`
63
113
64
-
In addition to the provided standard attributes, you can configure [Custom Attributes](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-custom-attributes). These are attributes that are typically unique to your use case, such as a tenant ID. Currently Amplify Auth does not support custom attributes in the `userAttributes` property, however you can [configure your auth resource to accept custom attributes using the AWS Cloud Development Kit (AWS CDK)](/[platform]/build-a-backend/auth/modify-resources-with-cdk/#custom-attributes).
114
+
Shown in the snippet above, `String` and `Number` can be assigned minimum and maximum constraints. This is useful to defer simple validations to the underlying service, although does not extend to complex validations such as matching against a regular expression.
65
115
66
-
###Next steps
116
+
## Next steps
67
117
118
+
-[Learn how attributes are surfaced to tokens](/[platform]/build-a-backend/auth/concepts/tokens-and-credentials/)
68
119
-[Learn how to manage your user attributes](/[platform]/build-a-backend/auth/connect-your-frontend/manage-user-attributes)
Copy file name to clipboardExpand all lines: src/pages/[platform]/build-a-backend/auth/connect-your-frontend/manage-user-attributes/index.mdx
+28-27Lines changed: 28 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ export function getStaticProps() {
31
31
User attributes such as email address, phone number help you identify individual users. Defining the user attributes you include for your user profiles makes user data easy to manage at scale. This information will help you personalize user journeys, tailor content, provide intuitive account control, and more. You can capture information upfront during sign-up or enable customers to update their profile after sign-up. In this section we take a closer look at working with user attributes, how to set them up and manage them.
You can create user attributes during sign-up or when the user is authenticated. To do this as part of sign-up you can pass them in the `userAttributes` object of the `signUp` API:
You can retrieve user attributes for your users to read in their profile using the `fetchUserAttributes` API. This helps you personalize their frontend experience as well as control what they will see.
Some attributes require confirmation for the attribute update to complete. If the attribute needs to be confirmed, part of the result of the `updateUserAttribute` or `updateUserAttributes` APIs will be `CONFIRM_ATTRIBUTE_WITH_CODE`. A confirmation code will be sent to the delivery medium mentioned in the delivery details. When the user gets the confirmation code, you can present a UI to the user to enter the code and invoke the `confirmUserAttribute` API with their input:
Copy file name to clipboardExpand all lines: src/pages/[platform]/build-a-backend/auth/modify-resources-with-cdk/index.mdx
-26Lines changed: 0 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,32 +57,6 @@ cfnUserPool.policies = {
57
57
};
58
58
```
59
59
60
-
## Custom Attributes
61
-
62
-
The following code will allow you to add custom attributes using the [Userpool schema](https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-cognito.CfnUserPool.html#schema) property with the L1 `cfnUserPool` construct.
0 commit comments