amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Email option not available for "How do you want your end users to sign in?" using amplify add auth.

Open zhzhang opened this issue 8 years ago • 33 comments

When configuring auth using this cli, the option for end users to sign in via email is not available as a configuration choice in the setup flow. Why is this the case, and what's the proper way to make email the sign-in method? Should I just use the username sign-in method but enforce that usernames and emails are the same?

zhzhang avatar Sep 03 '18 21:09 zhzhang

I am also interested in this option, is an option in awsmobile CLI but not in Amplify CLI.

UPDATE: I've found that, in the meantime, I can modify the cloudformation template in my local project repository, going to amplify/backend/auth/<project_name>/<project_name>-cloudformation-template.yml and adding right after the following lines:

Type: AWS::Cognito::UserPool
    Properties:
      UserPoolName: !Ref userPoolName

You can add:

      AliasAttributes:
        - 'email'
        - 'phone_number'

save it and then issue the command:

amplify push

By no means this is a permanent solution, this is just to get it going using the tool and being able to sign-in with a verified email address or phone number until a final solution is in place.

gustavo-rios avatar Sep 10 '18 15:09 gustavo-rios

When implmented, this should include email or phone_number options.

haverchuck avatar Sep 17 '18 21:09 haverchuck

Will this end up using the UsernameAttributes?

aiwilliams avatar Sep 18 '18 01:09 aiwilliams

I also need this. At the moment I can manually set up the "Users can use email as their "username" to sign up and sign in" option from the AWS console with MobileHub but I would really like to have the option to select it from the Amplify Cli especially since there are already the options to add other user attributes like given_name and family_name. Sign Up with email instead of a username is quite a standard case I think.

ghost avatar Oct 01 '18 12:10 ghost

Is there any update on this request? Being able to use the Amplify Cli to set up sign in with an email address instead of username? screen shot 2018-10-14 at 18 09 17

ghost avatar Oct 14 '18 17:10 ghost

I also find this a very strange and frustrating limitation. I even tried to create a new cognito and replace the one in the setup doc, but it just ended up making a NEW cognito with that given name instead (overwriting the ids etc).

angineering avatar Oct 24 '18 15:10 angineering

Finally figured this out looking at the template language. Under Type: AWS::Cognito::UserPool set

UsernameAttributes:
        - 'email'

This will create it with email instead of username setup.

link to documentation https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpool.html

angineering avatar Oct 24 '18 16:10 angineering

@angineering I am not sure I understand how you solved the problem? If you set up Cognito with the Amplify Cli (using the terminal and going through the custom set up options) it doesn't allow you to select Email as username. It gives you other options such as adding any attributes you want but not "Email as Username". Once Cognito is set up I don't seee how you can change the username setting... If you could explain in more detail how you did this I would be very grateful! Thanks

ghost avatar Oct 26 '18 09:10 ghost

@tamsynjennifer I did what @gustavo-rios did above. Go through the cli steps, then manually edit the mplify/backend/auth/<project_name>/<project_name>-cloudformation-template.yml before doing amplify push

angineering avatar Oct 26 '18 10:10 angineering

@angineering Thanks! I understand now. It worked for me too! :)

ghost avatar Oct 26 '18 20:10 ghost

Is not working for me, I'm tried with both solutions

UserPool:
# Created upon user selection
# Depends on SNS Role for Arn if MFA is enabled
  Type: AWS::Cognito::UserPool
  Properties:
    UserPoolName: !Ref userPoolName
    AliasAttributes:
      - 'email'
      - 'phone_number'
    UsernameAttributes:
      - 'email'
    Schema:

      -
        Name: family_name
        Required: true
        Mutable: true

I tried to use them separately

rcanessa89 avatar Dec 18 '18 06:12 rcanessa89

@rcanessa89 Did you edit the file before doing amplify push?

ghost avatar Dec 18 '18 18:12 ghost

Any updates on this?

evargast-old avatar Jan 28 '19 19:01 evargast-old

@rcanessa89 Only one of the aliasAttributes or usernameAttributes can be set in a User pool.

amirmishani avatar Jan 30 '19 01:01 amirmishani

Hee is what I did to make this work (after trying many variations:

In the YML file, add the following to the list of variables at the top of the page UsernameAttributes: Type: CommaDelimitedList

Then, in the UserPool: section below, add the following:

UsernameAttributes: !Ref UsernameAttributes

Then, in the parameters.json file, add:

"UsernameAttributes": ["email"],

This worked for me

fcwheeler avatar Feb 27 '19 22:02 fcwheeler

Adding the following to the CF template works:

UsernameAttributes:
        - 'email'

However the builtin Amplify signup forms are not compatible... at least not the aws-amplify-vue component I've tried it with.

Even passing in a signUpFields array to try and force it to stop displaying the username field, it just sticks one in there anyway, along with a phone number saying they are both required (The Cognito console does not list them as required)

dreams-and-thoughts avatar Mar 06 '19 06:03 dreams-and-thoughts

@comfytoday not 100% sure if vue behaves the same as angular but there you need to set hideAllDefaults like

signUpConfig = {
    hideAllDefaults: true,
    signUpFields: [
    {
      label: 'Name',
      key: 'name',
      required: true,
      displayOrder: 1,
      type: 'text',
    },
    {
      label: 'Email',
      key: 'username',
      required: true,
      displayOrder: 2,
      type: 'email',
    },
    {
      label: 'Password',
      key: 'password',
      required: true,
      displayOrder: 3,
      type: 'password',
    }
    ]
  };

h0raz avatar Mar 10 '19 10:03 h0raz

@h0raz Thank you!

Saved me some explaining....

This is the config I used in Vue. Found reference in another Github issue. It doesn't appear to be documented on the Vue side.

signUpConfig: {
          header: 'Sign Up',
          hideDefaults: true,
          signUpFields: [
            { ...

dreams-and-thoughts avatar Mar 10 '19 21:03 dreams-and-thoughts

const signUpConfig = {
  hiddenDefaults: ['username'],
  signUpFields: [
    {
      label: 'Email',
      key: 'username', // !!!
      required: true,
      displayOrder: 1,
      type: 'string',
      custom: false
    },
    {
      label: 'Password',
      key: 'password',
      required: true,
      displayOrder: 2,
      type: 'password',
      custom: false
    },
    {
      label: 'Phone Number',
      key: 'phone_number',
      required: true,
      displayOrder: 3,
      type: 'tel',
      custom: false
    }
  ]
};

export default withAuthenticator(App, { signUpConfig });

And adding:

yamlconfig

worked for me.

janhesters avatar Mar 14 '19 20:03 janhesters

If anyone is wondering how they can replace Username label on the Login screen, you can "translate it":


I18n.setLanguage('en');
I18n.putVocabularies({
  en: {
    'Username': 'Email'
  }
});

undsoft avatar Mar 29 '19 10:03 undsoft