Skip to content

Commit 5697e20

Browse files
authored
fix: Add newEmail to admin generateLink method (#904)
* fix: add newEmail to admin generateLink method * refactor: add asserts for generateLink
1 parent 4f5b853 commit 5697e20

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

packages/gotrue/lib/src/gotrue_admin_api.dart

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class GoTrueAdminApi {
5050
///
5151
/// This function should only be called on a server. Never expose your `service_role` key on the client.
5252
///
53-
// Requires either an email or phone
53+
/// Requires either an email or phone
5454
Future<UserResponse> createUser(AdminUserAttributes attributes) async {
5555
final options = GotrueRequestOptions(
5656
headers: _headers,
@@ -121,19 +121,41 @@ class GoTrueAdminApi {
121121
}
122122

123123
/// Generates links to be sent via email or other.
124+
///
125+
/// [password] is required for [GenerateLinkType.signup]
126+
///
127+
/// [newEmail] is required for [GenerateLinkType.emailChangeCurrent]
128+
/// and [GenerateLinkType.emailChangeNew]
129+
///
130+
/// [data] may be used to store the user's metadata.
131+
/// This maps to the `auth.users.user_metadata` column.
132+
/// Applicable for [GenerateLinkType.signup], [GenerateLinkType.invite],
133+
/// [GenerateLinkType.magiclink]
124134
Future<GenerateLinkResponse> generateLink({
125135
required GenerateLinkType type,
126136
required String email,
137+
String? newEmail,
127138
String? password,
128139
Map<String, dynamic>? data,
129140
String? redirectTo,
130141
}) async {
142+
assert(
143+
!(type == GenerateLinkType.emailChangeCurrent ||
144+
type == GenerateLinkType.emailChangeNew) ||
145+
newEmail != null,
146+
'newEmail is required for emailChangeCurrent and emailChangeNew',
147+
);
148+
assert(
149+
type != GenerateLinkType.signup || password != null,
150+
'password is required for signup',
151+
);
131152
final body = {
132153
'email': email,
133154
'type': type.snakeCase,
134155
if (data != null) 'data': data,
135156
if (redirectTo != null) 'redirect_to': redirectTo,
136157
if (password != null) 'password': password,
158+
if (newEmail != null) 'new_email': newEmail,
137159
};
138160

139161
final fetchOptions = GotrueRequestOptions(headers: _headers, body: body);

0 commit comments

Comments
 (0)