I'm working on a VUE+Amplify project, it's almost done, but cognito does not offer mail duplication check, so i've to do it manually, as we know AWS has some triggers i'm using PreSignUp invoking a Lambda function, my code is:
var AWS = require("aws-sdk");
const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
exports.handler = function(event, context, callback) {
var params = {
UserPoolId: "us-east-1_xxxXXXxXX",
AttributesToGet: ["email"]
};
cognitoidentityserviceprovider.listUsers(params, (err, data) => {
if (err) {
console.log(err, err.stack);
callback(err) // here is the error return
} else {
data.Users.forEach(function(usuario) {
if(usuario.Attributes[0].Value == event.request.userAttributes.email){
return {};
}
});
callback(event);
}
});
}
but I dont understand what I am doing wrong, the lambda execution returns...
Object { code: "UserLambdaValidationException", name: "UserLambdaValidationException", message: "PreSignUp failed with error [object Object]." }
Any idea?
You need to return the event object
https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-sign-up.html