我使用 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)"
]
}