AWS Cognito: How to send only the confirmation code in the custom email message post-sign up lambda trigger?

0

The example code under the Custom message for sign-up example doesn't seem to be working. My tests show that in order for the custom message to be sent, one has to send both the codeParameter and the linkParameter, otherwise Cognito will ignore the custom message and send the default one. I would prefer not to send the link parameter because it reveals internal information such as the client_id of my Cognito user pool. Also, the default confirmation page that the link takes users to, does not provide the best account confirmation experience for our users.

My goal is to send a link in the email message that sends users to my website, with URL query parameters that carry both the username and the confirmation code. The idea being that once users land on my site, we will make a subsequent request to our backend API with the username and code parameter from the URL, to confirm the account.

Is this something that AWS Cognito currently supports? What other alternatives are there besides intercepting the CustomMessage_SignUp trigger source?

Edmar
질문됨 4달 전402회 조회
1개 답변
1
수락된 답변

Hello,

I see that you want to send a custom message to your users when they signup that will contain the link to your website along with the verification code and username. However, you tested using the code given in the doc [1] but it is not working as expected. You found that it is necessary to pass both codeParameter and the linkParameter in the code. Please feel free to correct me in case I misunderstood your concern.

I replicated at my end with the sample code mentioned in the doc [1] and I verified that it is working as expected. I performed some trial and error operations and found when the default configuration of cognito userpool to confirm the user is set with verification link, in that case the custom message lambda gets triggered but only the default verification link is sent by Cognito. However, if the default configuration of cognito userpool to confirm the user is set with verification code then the sample code works fine and the verification code is sent as per the lambda trigger. Please follow the below steps to verify the configuration of the userpool:

  1. Open the desired Cognito userpool.
  2. Go to “Messaging” section
  3. At the bottom, go to “Message templates” section
  4. Select “Verification message” and click on edit
  5. Select verification type as “Code” (if not selected previously)
  6. Save Changes.

Once the above configuration has been done, go to “Userpool properties” section and attach the sample lambda function as Custom message Lambda trigger. Now, when the user sign-up, the lambda will get triggered and the verification code will be sent to the user with the email format mentioned in the sample code.

Note: there is no requirement for the linkParameter with the above steps.

You can modify the sample code as per your requirements. Also, would like to inform you that if you are using Custom message Lambda trigger then CustomMessage_SignUp is the only trigger source to send the confirmation code post sign-up. Otherwise CustomMessage_ResendCode is the trigger to resend the confirmation code.

I hope the information provided above, proves helpful in addressing your queries. Should you have any further queries, please feel free to reach out to us, we would be more than glad to assist you in all possible ways!

Happy Cloud Computing!

——————————RESOURCES—————————

[1] https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-message.html#aws-lambda-triggers-custom-message-example

AWS
지원 엔지니어
답변함 4달 전
  • Thank you very much. Changing the verification type to "Code" was the solution. Maybe calling that out as a requirement in the documentation with the sample code could provide better direction for others that might run into this issue.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠