resend method
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}');
}
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();
}
}