confirmSignUp method
Future<SignUpResult>
confirmSignUp({
- required String username,
- required String confirmationCode,
- ConfirmSignUpOptions? options,
Confirm the current sign up for username
with the confirmationCode
provided by the user.
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> confirmUser({
required String username,
required String confirmationCode,
}) async {
try {
final result = await Amplify.Auth.confirmSignUp(
username: username,
confirmationCode: confirmationCode,
);
return _handleSignUpResult(result);
} on AuthException catch (e) {
safePrint('Error confirming user: ${e.message}');
}
}
After confirming the sign up, check the SignUpResult
object to check if
further confirmations are needed or if the sign up is complete.
Future<void> _handleSignUpResult(SignUpResult result) async {
switch (result.nextStep.signUpStep) {
case AuthSignUpStep.confirmSignUp:
final codeDeliveryDetails = result.nextStep.codeDeliveryDetails!;
_handleCodeDelivery(codeDeliveryDetails);
case AuthSignUpStep.done:
safePrint('Sign up is complete');
}
}
Prompt the user to check the destination of the delivered code by examining the returned AuthCodeDeliveryDetails object.
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<SignUpResult> confirmSignUp({
required String username,
required String confirmationCode,
ConfirmSignUpOptions? options,
}) =>
identifyCall(
AuthCategoryMethod.confirmSignUp,
() => defaultPlugin.confirmSignUp(
username: username,
confirmationCode: confirmationCode,
options: options,
),
);