Skip to content

Instantly share code, notes, and snippets.

@dfang
Last active August 19, 2020 17:34
Show Gist options
  • Save dfang/d701f52ef449c94bd070a0eee2a169f3 to your computer and use it in GitHub Desktop.
Save dfang/d701f52ef449c94bd070a0eee2a169f3 to your computer and use it in GitHub Desktop.
aws cognito UI customization

if you only need email and password fields in sign up and sign in page and you want to customize labals .....

<AmplifyAuthenticator>
    <AmplifySignIn
        headerText="Custom form"
        formFields={[
            {
                type: 'username',
                label: 'Custom Username Label',
                placeholder: 'custom username placeholder',
                required: true,
                handleInputChange: (event, cb) => {
                    console.log('custom username field');
                    //perform any actions needed
                    cb(event);
                },
            },
            {
                type: 'password',
                label: 'Custom Password Label',
                placeholder: 'custom password placeholder',
                required: true,
                handleInputChange: (event, cb) => {
                    console.log('custom pwd field');
                    cb(event);
                },
            },
        ]}
        slot="sign-in"
    />
    <AmplifySignUp
        headerText="Custom form"
        formFields={[
            {
                type: 'username',
                label: 'Custom Username Label',
                placeholder: 'custom username placeholder',
                required: true,
                handleInputChange: (event, cb) => {
                    console.log('custom username field');
                    //perform any actions needed
                    cb(event);
                },
            },
            {
                type: 'password',
                label: 'Custom Password Label',
                placeholder: 'custom password placeholder',
                required: true,
                handleInputChange: (event, cb) => {
                    console.log('custom pwd field');
                    cb(event);
                },
            },
        ]}
        slot="sign-up"
    />
    <AmplifySignOut></AmplifySignOut>
</AmplifyAuthenticator>
@dfang
Copy link
Author

dfang commented Aug 18, 2020

Amplify UI Components for react 有两种

  1. aws-amplify-react vs 2. @aws-amplify/ui-react

1是legacy的,2也有,不要搞混了,都有 withAuthenticator
legacy 的withAuthenticator 支持 通过signUpConfig的signUpFields 来自定义sign up 页面

2 需要
https://docs.amplify.aws/ui/auth/authenticator/q/framework/react#withauthenticator
https://docs.amplify.aws/ui/auth/authenticator/q/framework/react#customization

@dfang
Copy link
Author

dfang commented Aug 19, 2020

自定义登录:

  1. 如果只是简单的使用email和密码代替 username和密码,直接自定义Hosted UI就可以了。
    像什么使用手机号 接收 OTP 登录得 自定义整个流程了

  2. SignUp 只支持input type形式的自定义,假设你想加自定义字段 custom:role 注册页面想放 select 供选择是不行的

@dfang
Copy link
Author

dfang commented Aug 19, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment