首页 > 解决方案 > Lambda 函数未通过 Auth0 node-auth0 SDK 调用 auth0 方法

问题描述

我有一个 lambda 函数,它在将消息添加到 SQS 队列时触发。

该消息包含我希望连接到Auth0 节点 SDK的 userId 。

在 CloudWatch 中可以看到我的GetUserDetails(下)触发console.log

我可以在 Auth0 日志中看到来自调用的令牌请求,new ManagementClient但之后没有任何内容。

我的代码示例

import { ManagementClient } from 'auth0';

const auth0 = new ManagementClient({
  domain: 'xxx.auth0.com',
  clientId: 'xxx',
  clientSecret: 'xxx',
  scope: 'read:users update:users',
});

const GetUserDetails = userId => {
  console.log('userId', userId); <-- This fires and can be seen in CloudWatch

  auth0.getUser({ id: userId }, (err, resp) => { <-- Nothing happens no errors, no user details
    if (err) {
      console.log('my error', err);
      return err.message;
    }
    console.log(resp);
    return resp;
  });
};

标签: javascriptnode.jsaws-lambdaauth0

解决方案


我让它使用这种格式工作:

auth0
  .getUser(userId)
  .then(function(users) {
    console.log(users);
  })
  .catch(function(err) {
    console.log(err);
  });

推荐阅读