Skip to content

Instantly share code, notes, and snippets.

@salihgueler
Created August 26, 2022 15:11
Show Gist options
  • Save salihgueler/b1a4e244caee30b40b7f32b314aa2fd2 to your computer and use it in GitHub Desktop.
Save salihgueler/b1a4e244caee30b40b7f32b314aa2fd2 to your computer and use it in GitHub Desktop.
Future<void> _updateEmail() async {
setState(() {
_errorMessage = null;
});
// (1)
if (_showEmailUpdate && _emailFormKey.currentState!.validate()) {
try {
// (2)
final result = await Amplify.Auth.updateUserAttribute(
userAttributeKey: CognitoUserAttributeKey.email,
value: _emailController.text,
);
setState(() {
_showEmailUpdate = false;
});
// (3)
if (result.nextStep.updateAttributeStep == 'CONFIRM_ATTRIBUTE_WITH_CODE' && mounted) {
context.go('/confirm-user');
} else {
logger.info('Update completed');
}
} on Exception catch (error) {
logger.error('An error occurred: $error');
}
} else {
// (4)
setState(() {
_showEmailUpdate = true;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment