updateUserAttributes method

Future<Map<AuthUserAttributeKey, UpdateUserAttributeResult>> updateUserAttributes({
  1. required List<AuthUserAttribute> attributes,
  2. UpdateUserAttributesOptions? options,
})

Updates multiple user attributes at once.

Optionally accepts plugin options which allow customizing provider-specific behavior, e.g. the Cognito User Pool.

For more information, see the Amplify docs.

Examples

import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Future<void> updateUserAttributes() async {
  const attributes = [
    AuthUserAttribute(
      userAttributeKey: AuthUserAttributeKey.email,
      value: 'email@email.com',
    ),
    AuthUserAttribute(
      userAttributeKey: AuthUserAttributeKey.familyName,
      value: 'MyFamilyName',
    ),
  ];
  try {
    final result = await Amplify.Auth.updateUserAttributes(
      attributes: attributes,
    );
    result.forEach((key, value) {
      switch (value.nextStep.updateAttributeStep) {
        case AuthUpdateAttributeStep.confirmAttributeWithCode:
          final destination = value.nextStep.codeDeliveryDetails?.destination;
          safePrint('Confirmation code sent to $destination for $key');
        case AuthUpdateAttributeStep.done:
          safePrint('Update completed for $key');
      }
    });
  } on AuthException catch (e) {
    safePrint('Error updating user attributes: ${e.message}');
  }
}

Implementation

Future<Map<AuthUserAttributeKey, UpdateUserAttributeResult>>
    updateUserAttributes({
  required List<AuthUserAttribute> attributes,
  UpdateUserAttributesOptions? options,
}) =>
        identifyCall(
          AuthCategoryMethod.updateUserAttributes,
          () => defaultPlugin.updateUserAttributes(
            attributes: attributes,
            options: options,
          ),
        );