I'm trying do build a web application integrated with AWS Cognito.
When I create a lambda function, using Node.js 8.10, to return specific response object I get an error:
exports.handler = (event, context, callback) => {
event["response"] = {
"test": "testing"
}
event.done(null, event);
};
The code is simple:
WebApp Login -> Cognito User Pool -> Post Authentication Trigger -> Lambda function.
What I need is that when Cognito Post Authentication Trigger calls the lambda Function, and returns a response with an object, that response gets back to the WebApp.
My Login Submit Handler is something like:
handleLoginSubmit = async event => {
event.preventDefault();
this.props.isLoading(true);
if(this.validateForm()) {
this.props.isLoading(false);
return;
}
try {
await Auth.signIn(this.state.email, this.state.password);
Auth.currentAuthenticatedUser()
.then(user => {
console.log("cognito return", user);
this.props.userHasAuthenticated(true);
})
.catch(err => console.log("error: ",err));
} catch (e) {
console.log('error currentAuthenticatedUser: ', e);
this.props.isLoading(false);
}
}
Login works, ok.
But I can never retrieve my response.test that i'm trying to pass over.
How do I retrieve that response sent from lambda to Post Authentication trigger from Cognito?