I am using Cognito user pools to create and authentication system.
Everything works perfectly. However, there is one scenario that I cannot figure out a solution for.
When a user signs up, a confirmation code is sent to the user’s email.
Let’s say the user accidentally closed the tab and tried signing up with the same email. Then, an error message will show up stating that the user already exists. If the users heads to the log in page and logs in using his email. An error shows up stating that the user is not confirmed.
Basically, the user is stuck.
My question is, how can a user confirm their email if the current sign up page was closed? How can I redirect the user to a confirmation page?
2
Answers
I came accross the exact same problem. The only but simple solution I found is to change the verification type from code to link. This is done within the verifcation message settings under messaging.
After doing that the user does not get a code anymore, instead he gets a link to click on. When he later comes back to the log in page, he is confirmed already and can enter his credentials right away.
I used Cognito triggers to solve this problem.
So the solution is to write a pre-authentication lambda function which triggers when user try to sign-in.
The lambda function looks like this
This helps a user to know whether the user exists in Cognito user pool and they are not confirmed.
This exception can be tracked like this
With this info we can redirect our page to confirmation page and use Cognito’s
resendConfirmationCode
method to send the verification code.This helps to confirm the Cognito user.