首页 > 解决方案 > AWS Cognito Trigger Post Authenticated - Lambda Nodejs 8.10 - 返回自定义响应错误 TypeError:无法设置属性

问题描述

我正在尝试构建一个与 AWS Cognito 集成的 Web 应用程序。

当我使用 Node.js 8.10 创建一个 lambda 函数来返回特定的响应对象时,我收到一个错误:

exports.handler = (event, context, callback) => {
  event["response"] = {
        "test": "testing"
      }
  event.done(null, event);
};

代码很简单:

WebApp 登录 -> Cognito 用户池 -> 身份验证后触发器 -> Lambda 函数。

我需要的是,当 Cognito Post Authentication Trigger 调用 lambda 函数并返回带有对象的响应时,该响应会返回给 WebApp。

我的登录提交处理程序类似于:

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);
  }
}

登录工作,好的。

但我永远无法检索我试图通过的 response.test。

如何检索从 lambda 发送到 Cognito 的 Post Authentication 触发器的响应?

标签: node.jsamazon-web-servicesaws-lambdaamazon-cognito

解决方案


推荐阅读