Skip to content

Instantly share code, notes, and snippets.

@salihgueler
Created August 26, 2022 15:17
Show Gist options
  • Save salihgueler/c2a7a60d8e09d8bb5a56da6a27dd1209 to your computer and use it in GitHub Desktop.
Save salihgueler/c2a7a60d8e09d8bb5a56da6a27dd1209 to your computer and use it in GitHub Desktop.
Future<void> _updatePassword() async {
setState(() {
_errorMessage = null;
});
// (1)
if (_showPasswordUpdate && _passwordFormKey.currentState!.validate()) {
try {
await Amplify.Auth.updatePassword(
newPassword: _newPasswordController.text,
oldPassword: _passwordController.text,
);
setState(() {
_showPasswordUpdate = false;
});
// (3)
} on NotAuthorizedException {
setState(() {
_errorMessage = 'Old password is wrong. Please try again';
});
} on Exception catch(error) {
setState(() {
_errorMessage = 'An unexpected error has happened. Check the logs for detail';
});
logger.error(error.toString());
}
} else {
// (4)
setState(() {
_showPasswordUpdate = true;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment