sendUserAttributeVerificationCode method

Future<SendUserAttributeVerificationCodeResult> sendUserAttributeVerificationCode({
  1. required AuthUserAttributeKey userAttributeKey,
  2. SendUserAttributeVerificationCodeOptions? options,
})

Sends a confirmation code for the existing value for the given userAttributeKey.

This API can be used to confirm an attribute that was not confirmed during the sign up flow.

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

Examples

import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Future<void> resendVerificationCode() async {
  try {
    final result = await Amplify.Auth.sendUserAttributeVerificationCode(
      userAttributeKey: AuthUserAttributeKey.email,
    );
    _handleCodeDelivery(result.codeDeliveryDetails);
  } on AuthException catch (e) {
    safePrint('Error resending code: ${e.message}');
  }
}

The details of where the code will be delivered are returned in the result's SendUserAttributeVerificationCodeResult.codeDeliveryDetails property and should be used to prompt the user on where to look for the code.

void _handleCodeDelivery(AuthCodeDeliveryDetails codeDeliveryDetails) {
  safePrint(
    'A confirmation code has been sent to ${codeDeliveryDetails.destination}. '
    'Please check your ${codeDeliveryDetails.deliveryMedium.name} for the code.',
  );
}

Implementation

Future<SendUserAttributeVerificationCodeResult>
    sendUserAttributeVerificationCode({
  required AuthUserAttributeKey userAttributeKey,
  SendUserAttributeVerificationCodeOptions? options,
}) =>
        identifyCall(
          AuthCategoryMethod.sendUserAttributeVerificationCode,
          () => defaultPlugin.sendUserAttributeVerificationCode(
            userAttributeKey: userAttributeKey,
            options: options,
          ),
        );