resend method

Future<ResendResponse> resend({
  1. String? email,
  2. String? phone,
  3. required OtpType type,
  4. String? emailRedirectTo,
  5. String? captchaToken,
})

Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.

For type of OtpType.signup or OtpType.emailChange email must be provided, and for type or OtpType.sms or OtpType.phoneChange, phone must be provided

Implementation

Future<ResendResponse> resend({
  String? email,
  String? phone,
  required OtpType type,
  String? emailRedirectTo,
  String? captchaToken,
}) async {
  assert((email != null && phone == null) || (email == null && phone != null),
      '`email` or `phone` needs to be specified.');
  if (email != null) {
    assert([OtpType.signup, OtpType.emailChange].contains(type),
        'email must be provided for type ${type.name}');
  }
  if (phone != null) {
    assert([OtpType.sms, OtpType.phoneChange].contains(type),
        'phone must be provided for type ${type.name}');
  }

  if (type != OtpType.emailChange && type != OtpType.phoneChange) {
    _removeSession();
  }

  final body = {
    if (email != null) 'email': email,
    if (phone != null) 'phone': phone,
    'type': type.snakeCase,
    'gotrue_meta_security': {'captcha_token': captchaToken},
  };

  final options = GotrueRequestOptions(
    headers: _headers,
    body: body,
    redirectTo: emailRedirectTo,
  );

  final response = await _fetch.request(
    '$_url/resend',
    RequestMethodType.post,
    options: options,
  );

  if ((response as Map).containsKey(['message_id'])) {
    return ResendResponse(messageId: response['message_id']);
  } else {
    return ResendResponse();
  }
}