1

我使用 Amplify 和 Cognito 后端来验证我的用户,本质上是作为 LDAP 实现。这一切都已配置并且工作正常。用户在用户池中设置,并正确验证。(注意:我使用的是默认的 Amplify 控件,因此它按预期工作)。

但是,现在我希望能够提取经过身份验证的用户及其所有数据(包括用户属性),以便我可以更新用户。作为第一步,我试图将经过身份验证的用户登录到控制台。最终,我将使用这个钩子通过从数据库中提取一些数据进行更新来更新用户属性。

这是我正在尝试使用的代码片段

exports.handler = async (event, context, callback) => {

    const Amplify = require('@aws-amplify/core')
    const Auth = require('@aws-amplify/auth')

    console.log("Amplify object: %o", Amplify)
    console.log("Auth object: %o", Auth)

    Amplify.configure({
        Auth: {
                identityPoolId: 'XXXX',
                region: event.region,
                userPoolId: event.userPoolId
        }
    });
    
    console.log("about to get current user");
    Auth.currentAuthenticatedUser().then(user => console.log(user));
    console.log("got current user and logged");
}

这是输出的几个片段......

INFO    Amplify object: {
  [__esModule]: true,
  Amplify: [Function: Amplify] {
    [length]: 0,
    [name]: 'Amplify',
    [prototype]: Amplify { [constructor]: [Circular] },
    register: [Function] {
      [length]: 1,
      [name]: '',
      [prototype]: { [constructor]: [Circular] }
    },
    configure: [Function] {
      [length]: 1,
      [name]: '',
      [prototype]: { [constructor]: [Circular] }
    },
    addPluggable: [Function] {
      [length]: 1,
      [name]: '',
      [prototype]: { [constructor]: [Circular] }
    },
    _components: [

INFO    Auth object: {
  [__esModule]: true,
  Auth: AuthClass {
    userPool: null,
    user: null,
    oAuthFlowInProgress: false,
    currentUserCredentials: [Function: bound ] { [length]: 0, [name]: 'bound ' },

我收到的错误是:

ERROR   Invoke Error    
{
    "errorType": "TypeError",
    "errorMessage": "Amplify.configure is not a function",
    "stack": [
        "TypeError: Amplify.configure is not a function",
        "    at Runtime.exports.handler (/var/task/index.js:171:13)",
        "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
    ]
}
4

2 回答 2

0

根据github 上的这个问题, Amplify 不能在 Node 中使用,因为它是一个前端库。

于 2020-10-05T18:20:02.770 回答
0

这个问题的答案是我需要在我的 package.json 中使用 aws lib。我已经包含它,但它不可用。嗬!

于 2020-10-06T19:26:36.790 回答