'how to update custom attributes of user in aws cognito
I'm integrating the stripe into the MERN app. On the stripe webhook call, I need to update the user custom attributes (Cognito). Is there any possible way to find the user using email in the pool and update its custom attributes?
I have tried (function:listUsers) this code to get the user but it doesn't provide the custom variables of the user.
const params = {
UserPoolId: AWS_POOL_ID,
AttributesToGet: ["email"],
};
new Promise((resolve, reject) => {
AWS.config.update({
region: AWS_REGION,
accessKeyId: AWS_ACCESS_PUBLIC,
secretAccessKey: AWS_ACCESS_SECRET,
});
const cognitoIdentityServiceProvider =
new AWS.CognitoIdentityServiceProvider();
cognitoIdentityServiceProvider.listUsers(params, (err, data) => {
if (err) {
console.log("cognito err::", err);
reject(err);
} else {
console.log("cognito data:", data);
resolve(data);
}
});
});
Response:
[
{
Username: '15a2-c98c-43a5-63c',
Attributes: [
{ Name: 'email', Value: '[email protected]' }
],
UserCreateDate: 2021-12-02T11:33:37.561Z,
UserLastModifiedDate: 2021-12-02T11:35:24.956Z,
Enabled: true,
UserStatus: 'CONFIRMED'
},
{
Username: '15ff633f-41faa9',
Attributes: [
{ Name: 'email', Value: '[email protected]' }
],,
UserCreateDate: 2021-09-17T14:37:12.943Z,
UserLastModifiedDate: 2021-09-18T04:08:25.443Z,
Enabled: true,
UserStatus: 'CONFIRMED'
}
]
but I need to get and update the custom variables only email available for finding user
Solution 1:[1]
You are passing in email in the AttributesToGet property in the parameters passed to the call to list the user. Based on this documentation, if that array is not included, all attributes will be returned, including the custom attributes from Cognito, which should have the prefix of custom:.
You will also be able to update the user's custom attributes using this function.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mary Carrigan |
