resetPasswordForEmail method

Future<void> resetPasswordForEmail(
  1. String email, {
  2. String? redirectTo,
  3. String? captchaToken,
})

Sends a reset request to an email address.

Implementation

Future<void> resetPasswordForEmail(
  String email, {
  String? redirectTo,
  String? captchaToken,
}) async {
  String? codeChallenge;
  if (_flowType == AuthFlowType.pkce) {
    assert(_asyncStorage != null,
        'You need to provide asyncStorage to perform pkce flow.');
    final codeVerifier = generatePKCEVerifier();
    await _asyncStorage!.setItem(
      key: '${Constants.defaultStorageKey}-code-verifier',
      value: '$codeVerifier/${AuthChangeEvent.passwordRecovery.name}',
    );
    codeChallenge = generatePKCEChallenge(codeVerifier);
  }

  final body = {
    'email': email,
    'gotrue_meta_security': {'captcha_token': captchaToken},
    'code_challenge': codeChallenge,
    'code_challenge_method': codeChallenge != null ? 's256' : null,
  };

  final fetchOptions = GotrueRequestOptions(
    headers: _headers,
    body: body,
    redirectTo: redirectTo,
  );
  await _fetch.request(
    '$_url/recover',
    RequestMethodType.post,
    options: fetchOptions,
  );
}