in aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.java [896:963]
public void updateUserAttributes(
@NonNull List<AuthUserAttribute> attributes,
@NonNull AuthUpdateUserAttributesOptions options,
@NonNull Consumer<Map<AuthUserAttributeKey, AuthUpdateAttributeResult>> onSuccess,
@NonNull Consumer<AuthException> onError
) {
final Map<String, String> clientMetadata = new HashMap<>();
if (options instanceof AWSCognitoAuthUpdateUserAttributesOptions) {
AWSCognitoAuthUpdateUserAttributesOptions cognitoOptions =
(AWSCognitoAuthUpdateUserAttributesOptions) options;
clientMetadata.putAll(cognitoOptions.getMetadata());
}
Map<String, String> attributesMap = new HashMap<>();
for (AuthUserAttribute attribute : attributes) {
attributesMap.put(attribute.getKey().getKeyString(), attribute.getValue());
}
awsMobileClient.updateUserAttributes(
attributesMap,
clientMetadata,
new Callback<List<UserCodeDeliveryDetails>>() {
@Override
public void onResult(List<UserCodeDeliveryDetails> result) {
Map<String, UserCodeDeliveryDetails> codeDetailsMap = new HashMap<>();
Map<AuthUserAttributeKey, AuthUpdateAttributeResult> resultMap = new HashMap<>();
for (UserCodeDeliveryDetails details : result) {
codeDetailsMap.put(details.getAttributeName(), details);
}
for (String attributeKey : attributesMap.keySet()) {
if (codeDetailsMap.containsKey(attributeKey)) {
resultMap.put(AuthUserAttributeKey.custom(attributeKey),
new AuthUpdateAttributeResult(
true,
new AuthNextUpdateAttributeStep(
AuthUpdateAttributeStep.
CONFIRM_ATTRIBUTE_WITH_CODE,
Collections.emptyMap(),
convertCodeDeliveryDetails(codeDetailsMap.get(attributeKey)))
));
} else {
resultMap.put(AuthUserAttributeKey.custom(attributeKey),
new AuthUpdateAttributeResult(
true,
new AuthNextUpdateAttributeStep(
AuthUpdateAttributeStep.
DONE,
Collections.emptyMap(),
null)
));
}
}
onSuccess.accept(resultMap);
}
@Override
public void onError(Exception error) {
onError.accept(new AuthException(
"Failed to update user attributes",
error,
"See attached exception for more details"
));
}
});
}