Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth): adds hub events to updateUserAttributes api #10731

Merged
merged 14 commits into from Dec 7, 2022
Merged
4 changes: 2 additions & 2 deletions packages/amazon-cognito-identity-js/src/CognitoUser.js
Expand Up @@ -1125,13 +1125,13 @@ export default class CognitoUser {
UserAttributes: attributes,
ClientMetadata: clientMetadata,
},
err => {
(err,result) => {
if (err) {
return callback(err, null);
}

// update cached user
return this.getUserData(() => callback(null, 'SUCCESS'), {
helgabalashova marked this conversation as resolved.
Show resolved Hide resolved
return this.getUserData(() => callback(null, result), {
bypassCache: true,
});
}
Expand Down
28 changes: 27 additions & 1 deletion packages/auth/src/Auth.ts
Expand Up @@ -53,6 +53,7 @@ import {
CognitoRefreshToken,
CognitoAccessToken,
NodeCallback,
CodeDeliveryDetails,
} from 'amazon-cognito-identity-js';

import { parse } from 'url';
Expand Down Expand Up @@ -1425,16 +1426,41 @@ export class AuthClass {
attributeList,
(err, result) => {
if (err) {
dispatchAuthEvent('updateUserAttributes_failure', err, 'Failed to update attributes');
return reject(err);
} else {
return resolve(result);
const attrs = this.createUpdateAttributesResultList(attributes as Record<string, string>, result.CodeDeliveryDetailsList);
dispatchAuthEvent('updateUserAttributes', attrs, 'Attributes successfully updated');
return resolve('SUCCESS');
}
},
clientMetadata
);
});
});
}

private createUpdateAttributesResultList(
helgabalashova marked this conversation as resolved.
Show resolved Hide resolved
attributes: Record<string, string>,
codeDeliveryDetailsList?: CodeDeliveryDetails []
): Record<string, string> {
const attrs = {};
Object.keys(attributes).forEach(key => {
attrs[key] = {
isUpdated: true
};
if (codeDeliveryDetailsList) {
const codeDeliveryDetails = codeDeliveryDetailsList.find(value => value.AttributeName === key);
helgabalashova marked this conversation as resolved.
Show resolved Hide resolved
if (codeDeliveryDetails) {
attrs[key].isUpdated = false;
attrs[key].codeDeliveryDetails = codeDeliveryDetails;
}
}

});
return attrs;
}

/**
* Return user attributes
* @param {Object} user - The CognitoUser object
Expand Down