Skip to content

Commit

Permalink
Add example for how to customize Sign Up (#552)
Browse files Browse the repository at this point in the history
Co-authored-by: Eddie Keller <[email protected]>
  • Loading branch information
ericclemmons and eddiekeller authored Oct 26, 2021
1 parent ad490a7 commit bba3242
Show file tree
Hide file tree
Showing 43 changed files with 1,414 additions and 422 deletions.
46 changes: 46 additions & 0 deletions .changeset/bump-versions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
'@aws-amplify/ui': patch
'@aws-amplify/ui-react': patch
---

`@aws-amplify/ui-react` supports validation & re-use & customization of `Authenticator.SignUp.FormFields` via `components` & `services`:

```js
<Authenticator
components={{
SignUp: {
FormFields() {
const { validationErrors } = useAuthenticator();
return (
<>
<TextField
label="Preferred Username"
labelHidden={true}
name="preferred_username"
placeholder="Preferred Username"
/>
<Authenticator.SignUp.FormFields />
<CheckboxField
errorMessage={validationErrors.acknowledgement}
hasError={!!validationErrors.acknowledgement}
name="acknowledgement"
value="yes"
>
I agree with the Terms & Conditions
</CheckboxField>
</>
);
},
},
}}
services={{
async validateCustomSignUp(formData) {
if (!formData.acknowledgement) {
return {
acknowledgement: 'You must agree to the Terms & Conditions',
};
}
},
}}
/>
```
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/*.d.ts linguist-generated=true
**/.graphqlconfig.yml linguist-generated=true
**/amplify/** linguist-generated=true
yarn.lock linguist-generated=true
63 changes: 62 additions & 1 deletion docs/src/pages/ui/components/authenticator/index.page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
title: Authenticator
---

import { Authenticator, Alert } from '@aws-amplify/ui-react';
import {
Alert,
Authenticator,
CheckboxField,
Link,
TextField,
useAuthenticator,
} from '@aws-amplify/ui-react';
import { Example } from '@/components/Example';
import { Feature } from '@/components/Feature';
import { Fragment } from '@/components/Fragment';
Expand Down Expand Up @@ -146,6 +153,60 @@ For your [configured social providers](https://docs.amplify.aws/lib/auth/social/

## Customization

### Sign Up Fields

The following example customizes the Sign Up screen with:

- Prepending custom `preferred_username` field
- Re-using the default form fields
- Appending a custom "Terms & Conditions" checkbox with custom validation

```tsx{3-11,28-48,51-57} file=../../../../../../examples/next/pages/ui/components/authenticator/custom-sign-up-fields/index.page.tsx

```

<Example>
<Authenticator
initialState="signUp"
loginMechanisms={['email']}
components={{
SignUp: {
FormFields() {
const { validationErrors } = useAuthenticator();
return (
<>
<TextField
label="Preferred Username"
labelHidden={true}
name="preferred_username"
placeholder="Preferred Username"
/>
<Authenticator.SignUp.FormFields />
<CheckboxField
errorMessage={validationErrors.acknowledgement}
hasError={!!validationErrors.acknowledgement}
name="acknowledgement"
value="yes"
>
I agree with the Terms & Conditions
</CheckboxField>
</>
);
},
},
}}
services={{
async validateCustomSignUp(formData) {
if (!formData.acknowledgement) {
return {
acknowledgement: 'You must agree to the Terms & Conditions',
};
}
},
}}
/>
</Example>

### Internationalization (I18n)

The `Authenticator` ships with [translations](https:/aws-amplify/amplify-ui/blob/main/packages/ui/src/i18n/translations.ts) for:
Expand Down
21 changes: 21 additions & 0 deletions environments/auth-with-email-and-custom-attributes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#amplify-do-not-edit-begin
amplify/\#current-cloud-backend
amplify/.config/local-*
amplify/logs
amplify/mock-data
amplify/backend/amplify-meta.json
amplify/backend/awscloudformation
amplify/backend/.temp
build/
dist/
node_modules/
aws-exports.js
awsconfiguration.json
amplifyconfiguration.json
amplifyconfiguration.dart
amplify-build-config.json
amplify-gradle-config.json
amplifytools.xcconfig
.secret-*
**.sample
#amplify-do-not-edit-end
22 changes: 22 additions & 0 deletions environments/auth-with-email-and-custom-attributes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auth with Email & Custom Attributes

This backend is configured with Amplify Admin UI & cloned with Amplify CLI v6.3.1:

- Authentication

- `Email` login mechanism
- Preferred Username (`preferred_username`) custom attribute

## Using this Backend

External contributors can re-create this backend by running:

```shell
amplify pull
```

Internal (Amplify UI team) contributors can use this backend directly by running:

```shell
amplify pull --appId di3yvcoio2o2w --envName staging --yes
```

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bba3242

Please sign in to comment.