2

I'm working on an serverless authentication and I've got a problem with sending confirmation email. When I create a user by AWS Console, the user is created and email with confirmation code is sent. But when I do a request to API, user is created in Cognito but no email is sent. What could be wrong with my code or request?

This is Cognito resource defined in serverless.yml:

CognitoUserPool:
    Type: AWS::Cognito::UserPool
    Properties:
      UserPoolName: ${self:service}-${self:provider.stage}-user-pool
      UsernameAttributes:
        - email
      AutoVerifiedAttributes:
        - email
      EmailConfiguration:
        EmailSendingAccount: COGNITO_DEFAULT

And it is request which I send to API:

POST / HTTP/1.1
Host: cognito-idp.eu-central-1.amazonaws.com
X-Amz-Target: AWSCognitoIdentityProviderService.SignUp
X-Amz-User-Agent: aws-amplify/0.1.x js amplify-authenticator
Content-Type: application/x-amz-json-1.1
Content-Length: ###

{
    "ClientId": "####################",
    "Username": "######@###.##",
    "Password": "####################",
    "ValidationData": null
}
Michał Miler
  • 152
  • 1
  • 9

2 Answers2

1

I resolved the problem by creating preSignUp lambda trigger with auto-confirming user:

const handler: PreSignUpTriggerHandler = async (event: PreSignUpTriggerEvent, context, callback) => {
  event.response.autoConfirmUser = true;

  callback(null, event);
};

Docs

AWS: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-sign-up.html Serverless: https://www.serverless.com/framework/docs/providers/aws/events/cognito-user-pool/

Michał Miler
  • 152
  • 1
  • 9
0

I work with different framework (Amplify), but as the both frameworks use Cognito User pools, I guess the issue would be that you are missing "domain name".

In AWS Console, check your User Pool, then in (left panel) find "App integration" and then open and setup "Domain Name".

Again, I am just guessing (sorry, if my advice will not help), but I experienced similar problem.

Stefan Majiros
  • 444
  • 7
  • 11