从 cognito 检索电子邮件

问题描述 投票:0回答:1

如何从 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;

};
aws-lambda amazon-cognito
1个回答
0
投票

用户的电子邮件保存在属性参数中,您应该能够像这样访问:

const emails = response.Users.map(user => {
            const emailAttribute = user.Attributes.find(attr => attr.Name === "email");
            return emailAttribute ? emailAttribute.Value : null;
        });

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html#API_ListUsers_ResponseElements

© www.soinside.com 2019 - 2024. All rights reserved.