Skip to content

Commit

Permalink
fix: Add newEmail to admin generateLink method (#904)
Browse files Browse the repository at this point in the history
* fix: add newEmail to admin generateLink method

* refactor: add asserts for generateLink
  • Loading branch information
Vinzent03 authored Apr 26, 2024
1 parent 4f5b853 commit 5697e20
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/gotrue/lib/src/gotrue_admin_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GoTrueAdminApi {
///
/// This function should only be called on a server. Never expose your `service_role` key on the client.
///
// Requires either an email or phone
/// Requires either an email or phone
Future<UserResponse> createUser(AdminUserAttributes attributes) async {
final options = GotrueRequestOptions(
headers: _headers,
Expand Down Expand Up @@ -121,19 +121,41 @@ class GoTrueAdminApi {
}

/// 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]
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);
Expand Down

0 comments on commit 5697e20

Please sign in to comment.