Search code examples
aws-amplifyaws-amplify-sdk-js

Set default country code in amplify authenticator signup component


Amplify authenticator is really convenient for common authentication flow.

By default, the country code is pre-select to +1, but the apps developed for other countries may want to default to another one.

Is there a way to change the default pre-selected value.

The official document doesn't include anything about this.

enter image description here


Solution

  • signUpConfig.defaultCountryCode to the rescure.

    After reading the source code of amplify-js. Here the code is.

    getDefaultDialCode() {
            return this.props.signUpConfig &&
                this.props.signUpConfig.defaultCountryCode &&
                countryDialCodes.indexOf(
                    `+${this.props.signUpConfig.defaultCountryCode}`
                ) !== -1
                ? `+${this.props.signUpConfig.defaultCountryCode}`
                : '+1';
        }
    

    So to use it. The HOC should like

    export default withAuthenticator(App, {signUpConfig: {defaultCountryCode: 61}})