updateUserAttribute method
Future<UpdateUserAttributeResult>
updateUserAttribute({
- required AuthUserAttributeKey userAttributeKey,
- required String value,
- UpdateUserAttributeOptions? options,
Updates a single user attribute.
To update multiple attributes, use updateUserAttributes instead.
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> updateUserEmail({
required String newEmail,
}) async {
try {
final result = await Amplify.Auth.updateUserAttribute(
userAttributeKey: AuthUserAttributeKey.email,
value: newEmail,
);
return _handleUpdateUserAttributeResult(result);
} on AuthException catch (e) {
safePrint('Error updating user attribute: ${e.message}');
}
}
If the update requires further confirmation, follow the next step returned
in the UpdateUserAttributeResult
.
void _handleUpdateUserAttributeResult(
UpdateUserAttributeResult result,
) {
switch (result.nextStep.updateAttributeStep) {
case AuthUpdateAttributeStep.confirmAttributeWithCode:
final codeDeliveryDetails = result.nextStep.codeDeliveryDetails!;
_handleCodeDelivery(codeDeliveryDetails);
case AuthUpdateAttributeStep.done:
safePrint('Successfully updated attribute');
}
}
Then call confirmUserAttribute with the delivered confirmation code.
Implementation
Future<UpdateUserAttributeResult> updateUserAttribute({
required AuthUserAttributeKey userAttributeKey,
required String value,
UpdateUserAttributeOptions? options,
}) =>
identifyCall(
AuthCategoryMethod.updateUserAttribute,
() => defaultPlugin.updateUserAttribute(
userAttributeKey: userAttributeKey,
value: value,
options: options,
),
);