I have the following method for signup in a typescript project.
import {CognitoIdentityProviderClient, SignUpCommand} from "@aws-sdk/client-cognito-identity-provider"
const UserPoolId = *************;
const ClientId = ***********;
const region = ***********
const config = {region: region}
export const registerUser = async (req, res) => {
try {
const { username, password } = req.body;
const client = new CognitoIdentityProviderClient(config);
const command = new SignUpCommand({
ClientId: ClientId,
Username: username,
Password: password,
UserAttributes: [{ Name: "email", Value: username }],
});
const response = await client.send(command);
res.status(200).json({ message: "User Created", username: username, password: password });
}
catch (err) {
console.log("FAILED")
console.log("Error"+ err.message)
res.status(500).json({ message: "User Not Created", error: err.message});
}
};
The purpose of this code is to sign up and add a user to the userpool that I have created in AWS Cognito User Pool. The function works to sign up the user. I can see that is works on the AWS userpool UI. However the user does not have a verified email through this SignUp method. When I add a user to the userpool from the AWS UI, automatically an email is sent to the user and the email is verified. Then there is a force reset on the password which must occur before the user may actually log in.
Is it possible to add that email notification in this sign up method? By doing that, I should be able to get the user to open the email and then the email would be verified. Without that email being sent, I'm not sure how a user would be able to verify their email and then go onto the next step to update their password.
Any assistance on this would be much appreciated!
This must be selected in
Edit attribute verification and user account confirmation
section:Once I added that, the notification email was sent as required.