Set up password change and recovery
Reset password
In order to reset your password, use the resetPassword api - this will send a code to the user attribute configured to receive such a reset code (e.g. email or SMS):
// Create this value on the class level to use as a statebool isPasswordReset = false;
...
Future<void> resetPassword() async { try { final result = await Amplify.Auth.resetPassword( username: 'myusername', ); setState(() { isPasswordReset = result.isPasswordReset; }); } on AmplifyException catch (e) { safePrint(e); }}
To complete the password reset process, invoke the confirmResetPassword api with the code you were sent and the new password you want.
Future<void> confirmResetPassword() async { try { await Amplify.Auth.confirmResetPassword( username: 'myusername', newPassword: 'mynewpassword', confirmationCode: '123456' ); } on AmplifyException catch (e) { print(e); }}
Change password
A signed in user can update their password using the updatePassword api:
Future<void> updatePassword() async { try { await Amplify.Auth.updatePassword( newPassword: 'mynewpassword', oldPassword: 'myoldpassword' ); } on AmplifyException catch (e) { print(e); }}