generateLink method
Generates links to be sent via email or other.
password
is required for GenerateLinkType.signup
newEmail
is required for GenerateLinkType.emailChangeCurrent
and GenerateLinkType.emailChangeNew
data
may be used to store the user's metadata.
This maps to the auth.users.user_metadata
column.
Applicable for GenerateLinkType.signup, GenerateLinkType.invite,
GenerateLinkType.magiclink
Implementation
Future<GenerateLinkResponse> generateLink({
required GenerateLinkType type,
required String email,
String? newEmail,
String? password,
Map<String, dynamic>? data,
String? redirectTo,
}) async {
assert(
!(type == GenerateLinkType.emailChangeCurrent ||
type == GenerateLinkType.emailChangeNew) ||
newEmail != null,
'newEmail is required for emailChangeCurrent and emailChangeNew',
);
assert(
type != GenerateLinkType.signup || password != null,
'password is required for signup',
);
final body = {
'email': email,
'type': type.snakeCase,
if (data != null) 'data': data,
if (redirectTo != null) 'redirect_to': redirectTo,
if (password != null) 'password': password,
if (newEmail != null) 'new_email': newEmail,
};
final fetchOptions = GotrueRequestOptions(headers: _headers, body: body);
final response = await _fetch.request(
'$_url/admin/generate_link',
RequestMethodType.post,
options: fetchOptions,
);
return GenerateLinkResponse.fromJson(response);
}