I have a lambda function that verifies user credentials. Upon success it should call another lambda function, as a destination, that generates a token. When I test the first function, it is successful but it does not call the destination which is the other lambda function. It only gives me the success message from the first function.
Function one
exports.handler = function (event, context) {
var id = event.email;
var params = {
TableName: "User",
KeyConditionExpression: "#email = :email",
ExpressionAttributeNames:{
"#email": "email",
},
ExpressionAttributeValues: {
":email": {S: event.email},
}
};
if (id && id !== '') {
dynamo.query(params, function (err, data, callback) {
if (err) {
context.done(err);
}
else {
var user = data.Items[0];
if (user) {
var encryptedParams = {
CiphertextBlob: Buffer.from(user.password.B),
};
kms.decrypt(encryptedParams, function (err, decrypteddata) {
if (err) {
console.log(err, err.stack);
context.done(err);
}
else {
if(event.password == decrypteddata.Plaintext.toString()) {
console.log("User authenticated");
}
}
});
}
}
});
}
else {
return {
statusCode: 400,
body: "No email provided."
}
}
};
Function two
exports.handler = async (event) => {
var expires = moment().add('days', 7).valueOf();
var token = jwt.encode({
iss: event.email,
exp: expires
}, app.get('jwtTokenSecret'));
const response = {
token: token,
express: expires,
statusCode: 200
};
console.log("token granted");
return response;
};