# Signup with AWS Cognito

**URL:** <https://discourse.sst.dev/t/signup-with-aws-cognito/130>\
**Category:** Chapter Comments\
**Created:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130 "2018-05-09T19:53:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/1 "2018-05-09T19:53:46Z")

</div>

_From @jayair on Mon Apr 10 2017 01:05:17 GMT+0000 (UTC)_  
  
Link to chapter - [http://serverless-stack.com/chapters/signup-with-aws-cognito.html](http://serverless-stack.com/chapters/signup-with-aws-cognito.html)  
  
_Copied from original issue: [https://github.com/AnomalyInnovations/serverless-stack-com/issues/46](https://github.com/AnomalyInnovations/serverless-stack-com/issues/46)_

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/2 "2018-05-09T19:53:47Z")

</div>

_From @DushyantShukla on Tue Sep 05 2017 17:15:28 GMT+0000 (UTC)_  
  
Is this code functional? As I was unable to register a new user. I found that the email attribute should be passed against the key email in the userAttributes parameter of [SignUp](http://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_SignUp.html) API. Finally, below is my updated signup() method which works just fine:

```auto
signup(email, password) {
        const userPool = new CognitoUserPool({
            UserPoolId: config.cognito.USER_POOL_ID,
            ClientId: config.cognito.APP_CLIENT_ID
        });
        const attributeList = [];
        attributeList.push(new CognitoUserAttribute({
            Name: 'email',
            Value: email
        }));
        return new Promise((resolve, reject) =>
            userPool.signUp(email, password, attributeList, null, (err, result) => {
                if (err) {
                    reject(err);
                    return;
                }
                resolve(result.user);
            })
        );
    }

```

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/3 "2018-05-09T19:53:47Z")

</div>

_From @jayair on Tue Sep 05 2017 19:30:44 GMT+0000 (UTC)_  
  
@DushyantShukla Yeah it is functional. The tutorial has been updated so that the `email` can be passed in as the username. You can read more about the update here - [https://github.com/AnomalyInnovations/serverless-stack-com/issues/123](https://github.com/AnomalyInnovations/serverless-stack-com/issues/123).

If you need to reference the old version of the tutorial, there is a hosted version here - https://59a70f2ccf321c2ccb15113f–serverless-stack.netlify.com.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/4 "2018-05-09T19:53:47Z")

</div>

_From @DushyantShukla on Wed Sep 06 2017 06:38:16 GMT+0000 (UTC)_  
  
Oops! Didn’t know that! I appreciate the response. Thanks!

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/5 "2018-05-09T19:53:48Z")

</div>

_From @QuantumInformation on Sun Oct 08 2017 08:33:03 GMT+0000 (UTC)_  
  
When a user signs up I get this screen

 ![image](https://yyz2.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/fd72d2e296ba5ae7e108415cf390f7218c22868a.png)

But I get an email link instead:

 ![image](https://yyz2.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/9952b1dcb88994f2703103b5912efe8d39bea984.png)

which takes me to this page

 ![image](https://yyz2.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/42854a4b098b9726bafbcb8b8200370dfd432adc.png)

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/6 "2018-05-09T19:53:48Z")

</div>

_From @QuantumInformation on Mon Oct 09 2017 10:44:13 GMT+0000 (UTC)_  
  
I rechecked my pool with the advice in [https://serverless-stack.com/chapters/create-a-cognito-user-pool.html](https://serverless-stack.com/chapters/create-a-cognito-user-pool.html) but it seems the same to me.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/7 "2018-05-09T19:53:48Z")

</div>

_From @jayair on Mon Oct 09 2017 23:10:48 GMT+0000 (UTC)_  
  
@QuantumInformation Hmm can you check this setting?

 ![screen shot 2017-10-09 at 7 06 20 pm copy](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/4ada1e5914c4d8e154ce64bc7eba2c9606ebebcb.jpg)

It should have defaulted to **Code** instead of **Link**.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/8 "2018-05-09T19:53:49Z")

</div>

_From @elnbado on Thu Oct 12 2017 12:19:05 GMT+0000 (UTC)_  
  
In `handleSubmit = async event =>`

I get the following Warning when calling:

```auto
  this.setState({
        newUser: newUser
  });

Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.

Please check the code for the Signup component.

```

Anyone else has this problem? Any ideas to resolve this?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/9 "2018-05-09T19:53:49Z")

</div>

_From @jayair on Thu Oct 12 2017 18:40:55 GMT+0000 (UTC)_  
  
@elnbado This happens usually when you make the `setState` call after you move away from the page. Is your app redirecting after you hit the Signup button?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/10 "2018-05-09T19:53:49Z")

</div>

_From @millergd on Fri Oct 20 2017 03:33:13 GMT+0000 (UTC)_  
  
For some reason, my signup() method did not work until I added an attribute list to the userPool.signUp() call. Is this out of date?

this is what my working code looks like:

```auto
signup(email, password) {
        const userPool = new CognitoUserPool({
            UserPoolId: config.cognito.USER_POOL_ID,
            ClientId: config.cognito.APP_CLIENT_ID
        });
        const attributeList = [];
        attributeList.push(new CognitoUserAttribute({
            Name: 'email',
            Value: email
        }));
        return new Promise((resolve, reject) =>
            userPool.signUp(email, password, attributeList, null, (err, result) => {
                if (err) {
                    reject(err);
                    return;
                }
                resolve(result.user);
            })
        );
    }

```

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/11 "2018-05-09T19:53:49Z")

</div>

_From @jayair on Fri Oct 20 2017 16:51:37 GMT+0000 (UTC)_  
  
@millergd The tutorial had been updated a while back to set the email as the username in the User Pool. This makes it so that you don’t have to set the attribute. You can read more about it here - [https://github.com/AnomalyInnovations/serverless-stack-com/issues/123](https://github.com/AnomalyInnovations/serverless-stack-com/issues/123).

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/12 "2018-05-09T19:53:50Z")

</div>

_From @millergd on Fri Oct 20 2017 17:03:44 GMT+0000 (UTC)_  
  
@jayair yeah it looks like I was using an older version of the tutorial and setting up the userpool different.

However, I don’t really understand the changes. Can you clarify what was the norm before and after the update?

```auto
Previously, we were manually setting using the email as a user’s username. There is one major issue
with this; the username cannot be changed in your Cognito User Pool. AWS fixed this by adding the
option of using the email as the username while logging in and signing up. 

```

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/13 "2018-05-09T19:53:50Z")

</div>

_From @jayair on Fri Oct 20 2017 18:54:52 GMT+0000 (UTC)_  
  
@millergd Yeah the issue with setting the email as the username manually (as we were doing before) was that the username in Cognito cannot be changed. So you would need to work around this in case your users need to change their email.

But with the new email as username setting that’s been introduced recently, the User Pool sets a unique string as the username internally. This allows you to change a user’s email (and username) easily.

Hopefully that makes sense. It is a bit confusing though.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/14 "2018-05-09T19:53:51Z")

</div>

_From @d0ruk on Thu Jan 04 2018 13:49:55 GMT+0000 (UTC)_  
  
@jayair

> setting the email as the username manually

Can you elaborate on this? Did you use to derive a dummy username from the email?

I am using aws-amplify for Auth. Signature of the [signUp function](https://github.com/aws/aws-amplify/blob/master/packages/aws-amplify/src/Auth/Auth.ts#L100) is

> signUp(username: string, password: string, email: string, phone\_number: string): Promise

I _have to_ supply a username. So I derive a username from the email, and do `signUp(dummyName, password, email)`. However, this way, the user gets a username she doesn’t even see. It’s some specific way of string manipulation my client does.

Thus, when the user logs in via her email, that same util function derives the same username, and makes the request to the user pool with that. So the e-mail is really not needed, the way I went about doing it.

Did you have to do it like the above? Make up a username?

* * *

p.s. From the looks of [this PR](https://github.com/aws/aws-amplify/pull/79/commits/379ee152863800ced366fdd58f72ee607445715a), the new signature will be;

`signUp(username: string, password: string, email: string|Array<Object>, phone_number: string): Promise<any>`

I think that will allow you to attach custom attributes to your user. However, that still seems to necessitate a username.

p.p.s When I try to signup with email in place of the username, AWS returns

> Username cannot be of email format, since user pool is configured for email alias.

Which is cryptic to me. When I try to verify the user, I again need to supply the derived username.

However, when logging in, I can use the e-mail address as is, apparently. So, the username is used only for the signup phase? I don’t need it afterwards?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/15 "2018-05-09T19:53:51Z")

</div>

_From @jayair on Fri Jan 05 2018 20:58:41 GMT+0000 (UTC)_  
  
@d0ruk We were setting the username manually. As in passing in the email as the username. The error you are getting is because you have the email as alias option enabled. This means users can login with either their username or email. But it does not allow usernames that are of the email format since you could have an unverified email as the username. In the tutorial we don’t use this option.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/16 "2018-05-09T19:53:51Z")

</div>

_From @d0ruk on Fri Jan 05 2018 21:20:32 GMT+0000 (UTC)_  
  
@jayair

Thus, if I don’t use any aliases, would the user pool accept signup/login flows with an email? As I linked above, the signUp() method requires a username.

I’m asking this because there might not be such an option in the aws-amplify API, yet. Cognito might be supportting it, however. I’m trying to discern what is possible with aws-amplify.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/17 "2018-05-09T19:53:52Z")

</div>

_From @jayair on Mon Jan 08 2018 02:33:31 GMT+0000 (UTC)_  
  
@d0ruk Yeah I’m not sure about amplify. Are you not able to change the User Pool settings from the AWS Console?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/18 "2018-05-09T19:53:52Z")

</div>

_From @d0ruk on Tue Jan 09 2018 15:32:14 GMT+0000 (UTC)_  
  
@jayair

I’m trying to figure out the .yaml representation of the userpool in the tutorial. That’s outside the scope of the book.

I’ll leave it as is (derive username for login/verify) since it works. I’ll note it somewhere here in case this turns out to be a no-no with aws-amplify.

Cheers.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/19 "2018-05-09T19:53:52Z")

</div>

_From @PraneshBalekai on Mon Feb 05 2018 12:57:13 GMT+0000 (UTC)_  
  
Is there a link/reference to how to register the user with an Identity pool after sign up?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:53pm UTC](https://discourse.sst.dev/t/signup-with-aws-cognito/130/20 "2018-05-09T19:53:53Z")

</div>

_From @jayair on Mon Feb 05 2018 18:30:29 GMT+0000 (UTC)_  
  
@PraneshBalekai What do you mean by registering a user with an Identity Pool?

[Next page](https://discourse.sst.dev/t/signup-with-aws-cognito/130.md?page=2)
