From 84628665c822e9bba111e30dd7c5d3ae1a79dd12 Mon Sep 17 00:00:00 2001 From: Nandor Krizbai Date: Thu, 29 May 2025 18:13:53 +0300 Subject: [PATCH 1/2] add soft-delete option to DeleteUser method --- Gotrue/AdminClient.cs | 4 ++-- Gotrue/Api.cs | 11 ++++++++--- Gotrue/Interfaces/IGotrueAdminClient.cs | 2 +- Gotrue/Interfaces/IGotrueApi.cs | 2 +- Gotrue/Interfaces/IGotrueStatelessClient.cs | 5 +++-- Gotrue/StatelessClient.cs | 4 ++-- GotrueTests/StatelessClientTests.cs | 2 +- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Gotrue/AdminClient.cs b/Gotrue/AdminClient.cs index 3e1c95a..c6f1d94 100644 --- a/Gotrue/AdminClient.cs +++ b/Gotrue/AdminClient.cs @@ -69,9 +69,9 @@ public async Task InviteUserByEmail(string email, InviteUserByEmailOptions } /// - public async Task DeleteUser(string uid) + public async Task DeleteUser(string uid, bool shouldSoftDelete = false) { - var result = await _api.DeleteUser(uid, _serviceKey); + var result = await _api.DeleteUser(_serviceKey, uid, shouldSoftDelete); result.ResponseMessage?.EnsureSuccessStatusCode(); return true; } diff --git a/Gotrue/Api.cs b/Gotrue/Api.cs index 76e14ce..036b807 100644 --- a/Gotrue/Api.cs +++ b/Gotrue/Api.cs @@ -738,12 +738,17 @@ public Task Reauthenticate(string userJwt) /// /// Delete a user /// - /// The user uid you want to remove. /// A valid JWT. Must be a full-access API key (e.g. service_role key). + /// The user uid you want to remove. + /// If true, then the user will be soft-deleted from the auth schema. Defaults to false. /// - public Task DeleteUser(string uid, string jwt) + public Task DeleteUser(string jwt, string uid, bool shouldSoftDelete = false) { - var data = new Dictionary(); + var data = new Dictionary + { + { "should_soft_delete", shouldSoftDelete } + }; + return Helpers.MakeRequest(HttpMethod.Delete, $"{Url}/admin/users/{uid}", data, CreateAuthedRequestHeaders(jwt)); } diff --git a/Gotrue/Interfaces/IGotrueAdminClient.cs b/Gotrue/Interfaces/IGotrueAdminClient.cs index 4d7a0b0..1555d08 100644 --- a/Gotrue/Interfaces/IGotrueAdminClient.cs +++ b/Gotrue/Interfaces/IGotrueAdminClient.cs @@ -35,7 +35,7 @@ public interface IGotrueAdminClient : IGettableHeaders /// Creates a user using the admin key (not the anonymous key). /// Used in trusted server environments, not client apps. /// - Task DeleteUser(string uid); + Task DeleteUser(string uid, bool shouldSoftDelete = false); /// /// Gets a user from a user's JWT. This is using the GoTrue server to validate a user's JWT. diff --git a/Gotrue/Interfaces/IGotrueApi.cs b/Gotrue/Interfaces/IGotrueApi.cs index 6f76bac..40e937e 100644 --- a/Gotrue/Interfaces/IGotrueApi.cs +++ b/Gotrue/Interfaces/IGotrueApi.cs @@ -14,7 +14,7 @@ public interface IGotrueApi : IGettableHeaders where TSession : Session { Task CreateUser(string jwt, AdminUserAttributes? attributes = null); - Task DeleteUser(string uid, string jwt); + Task DeleteUser(string jwt, string uid, bool shouldSoftDelete = false); Task GetUser(string jwt); Task GetUserById(string jwt, string userId); Task InviteUserByEmail(string email, string jwt, InviteUserByEmailOptions? options = null); diff --git a/Gotrue/Interfaces/IGotrueStatelessClient.cs b/Gotrue/Interfaces/IGotrueStatelessClient.cs index 538a912..338690e 100644 --- a/Gotrue/Interfaces/IGotrueStatelessClient.cs +++ b/Gotrue/Interfaces/IGotrueStatelessClient.cs @@ -40,11 +40,12 @@ public interface IGotrueStatelessClient /// /// Deletes a User. /// - /// /// this token needs role 'supabase_admin' or 'service_role' /// + /// + /// If true, then the user will be soft-deleted. Defaults to false. /// - Task DeleteUser(string uid, string serviceRoleToken, StatelessClientOptions options); + Task DeleteUser(string serviceRoleToken, StatelessClientOptions options, string uid, bool shouldSoftDelete = false); /// /// Logs in an existing user via a third-party provider. diff --git a/Gotrue/StatelessClient.cs b/Gotrue/StatelessClient.cs index 129b26d..62032e7 100644 --- a/Gotrue/StatelessClient.cs +++ b/Gotrue/StatelessClient.cs @@ -314,9 +314,9 @@ public async Task ResetPasswordForEmail(string email, StatelessClientOptio } /// - public async Task DeleteUser(string uid, string serviceRoleToken, StatelessClientOptions options) + public async Task DeleteUser(string serviceRoleToken, StatelessClientOptions options, string uid, bool shouldSoftDelete = false) { - var result = await GetApi(options).DeleteUser(uid, serviceRoleToken); + var result = await GetApi(options).DeleteUser(serviceRoleToken, uid, shouldSoftDelete); result.ResponseMessage?.EnsureSuccessStatusCode(); return true; } diff --git a/GotrueTests/StatelessClientTests.cs b/GotrueTests/StatelessClientTests.cs index a0deb8e..9656fb7 100644 --- a/GotrueTests/StatelessClientTests.cs +++ b/GotrueTests/StatelessClientTests.cs @@ -259,7 +259,7 @@ public async Task DeletesUser() var uid = session.User.Id; var serviceRoleKey = GenerateServiceRoleToken(); - var result = await _client.DeleteUser(uid, serviceRoleKey, Options); + var result = await _client.DeleteUser(serviceRoleKey, Options, uid); Assert.IsTrue(result); } From da4e7fe985331c9eb22f1713b7d64cd784fc10a2 Mon Sep 17 00:00:00 2001 From: Nandor Krizbai Date: Fri, 30 May 2025 11:11:39 +0300 Subject: [PATCH 2/2] Make parameter non-optional in helper class --- Gotrue/Api.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gotrue/Api.cs b/Gotrue/Api.cs index 036b807..5131adb 100644 --- a/Gotrue/Api.cs +++ b/Gotrue/Api.cs @@ -740,9 +740,9 @@ public Task Reauthenticate(string userJwt) /// /// A valid JWT. Must be a full-access API key (e.g. service_role key). /// The user uid you want to remove. - /// If true, then the user will be soft-deleted from the auth schema. Defaults to false. + /// If true, then the user will be soft-deleted. /// - public Task DeleteUser(string jwt, string uid, bool shouldSoftDelete = false) + public Task DeleteUser(string jwt, string uid, bool shouldSoftDelete) { var data = new Dictionary {