如何从 Cognito 客户端中的用户对象检索电子邮件?我也尝试过使用驼峰命名法和大写字母,但什么也没有。我正在尝试将其提供给 API 网关,以便我可以从前端运行身份验证功能
import {CognitoIdentityProviderClient, paginateListUsers} from '@aws-sdk/client-cognito-identity-provider';
const cognito = new CognitoIdentityProviderClient({});
export const handler = async function (event, context, callback) {
const paginator = paginateListUsers({client: cognito}, {
UserPoolId: '<region>',
AttributesToGet: ["email"],
Filter: '',
Limit: 60
});
let logins = [];
for await (const page of paginator) {
for (const user of page.Users) {
logins.push(
{
"username": user.Username,
"email": user.email
}
);
}
}
return logins;
};
用户的电子邮件保存在属性参数中,您应该能够像这样访问:
const emails = response.Users.map(user => {
const emailAttribute = user.Attributes.find(attr => attr.Name === "email");
return emailAttribute ? emailAttribute.Value : null;
});