Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 543
ivenxu Avatar asked Oct 18 '25 13:10

ivenxu


2 Answers

You can pass the dialCode in formFields.

{
  type: 'phone_number',
  dialCode: 27, // or '+27' 
  value: '5555555555',
}
like image 69
Arshad Avatar answered Oct 22 '25 05:10

Arshad


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}})
like image 21
ivenxu Avatar answered Oct 22 '25 06:10

ivenxu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!