From 5697e2060de1596626026a0f9ffd846435a6967a Mon Sep 17 00:00:00 2001 From: Vinzent Date: Fri, 26 Apr 2024 15:01:07 +0200 Subject: [PATCH] fix: Add newEmail to admin generateLink method (#904) * fix: add newEmail to admin generateLink method * refactor: add asserts for generateLink --- packages/gotrue/lib/src/gotrue_admin_api.dart | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/gotrue/lib/src/gotrue_admin_api.dart b/packages/gotrue/lib/src/gotrue_admin_api.dart index 1de22944..4fc987d9 100644 --- a/packages/gotrue/lib/src/gotrue_admin_api.dart +++ b/packages/gotrue/lib/src/gotrue_admin_api.dart @@ -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 createUser(AdminUserAttributes attributes) async { final options = GotrueRequestOptions( headers: _headers, @@ -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 generateLink({ required GenerateLinkType type, required String email, + String? newEmail, String? password, Map? 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);