finishPasswordReset method

Future<void> finishPasswordReset()

Completes the password reset process with a new password.

Use the passwordController to provide the new password. On success, updates the session manager and calls onAuthenticated. On failure, transitions to error state with the error message.

Implementation

Future<void> finishPasswordReset() async {
  await _guarded(EmailAuthState.authenticated, null, () async {
    final finishRequestToken = _finishRequestToken;
    if (finishRequestToken == null) {
      throw StateError('No password reset request was found to finish.');
    }

    await _emailEndpoint.finishPasswordReset(
      finishPasswordResetToken: finishRequestToken,
      newPassword: passwordController.text,
    );

    final authSuccess = await _emailEndpoint.login(
      email: emailController.text.trim(),
      password: passwordController.text,
    );

    await client.auth.updateSignedInUser(authSuccess);
  });
}