Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different email verification messages for sign-up and forgot-password

Using the AWS's Cognito one can gain a lot since most of the functionalities (if not all) are already implemented by AWS. But I've faced a situation which I'm not sure how to implement using Cognito. Consider the following two scenarios:

  • Sign up:

    1. User signs up by providing an email, and a password
    2. An email is sent to the user with a confirmation code
    3. User sends the username and confirmation code to complete the process
  • Forgot password:

    1. User requests a code by sending his / her username
    2. An email is sent to the user with the generated code in the previous step
    3. User resets the password by providing the username, the new password, and the code

The statements above are tailored according to how AWS Cognito is implemented. And as you can see, the two final steps require different input in each of the scenarios. Now, my question is why AWS Cognito uses the same email template (in the second step) for both of them?

AFAIK, there's only one template in Cognito ("Message customizations" section) and it is used regardless of the email is sent to confirm user's email ownership or user has requested for a password reset code.

This is a problem for me since I want the content of the two emails to be different. For starters, they should contain different links in them.

Is there a way to send two different emails for confirmation code and forgot password in Cognito?

like image 256
Mehran Avatar asked May 29 '18 19:05

Mehran


People also ask

What is password reset?

Reset password is the action of invalidating the current password for an account on a website, service, or device, and then creating a new one. A password may be reset using the settings of the software or service, or by contacting the customer service department.

How do I change my laravel password reset template?

Set up the reset password controller use App\Models\User; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; Then, implement the resetPassword() method which allows the user to reset their password, by adding code below to the body of the class.


1 Answers

As it turned out the answer is to use Custom message from Triggers. Cognito lets you specify lambda functions for the different event generated in a user pool. One of which is Custom message. This lambda function is called each time an email is about to be sent to the client. Using the input data given to the lambda function, one can realize which scenario it is and compose the correct content for that email.

Here's the link to the documentation:

https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-message.html

like image 51
Mehran Avatar answered Oct 18 '22 14:10

Mehran