Skip to content

Add soft-delete option to DeleteUser method #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gotrue/AdminClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public async Task<bool> InviteUserByEmail(string email, InviteUserByEmailOptions
}

/// <inheritdoc />
public async Task<bool> DeleteUser(string uid)
public async Task<bool> 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;
}
Expand Down
11 changes: 8 additions & 3 deletions Gotrue/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -738,12 +738,17 @@ public Task<BaseResponse> Reauthenticate(string userJwt)
/// <summary>
/// Delete a user
/// </summary>
/// <param name="uid">The user uid you want to remove.</param>
/// <param name="jwt">A valid JWT. Must be a full-access API key (e.g. service_role key).</param>
/// <param name="uid">The user uid you want to remove.</param>
/// <param name="shouldSoftDelete">If true, then the user will be soft-deleted.</param>
/// <returns></returns>
public Task<BaseResponse> DeleteUser(string uid, string jwt)
public Task<BaseResponse> DeleteUser(string jwt, string uid, bool shouldSoftDelete)
{
var data = new Dictionary<string, string>();
var data = new Dictionary<string, bool>
{
{ "should_soft_delete", shouldSoftDelete }
};

return Helpers.MakeRequest(HttpMethod.Delete, $"{Url}/admin/users/{uid}", data, CreateAuthedRequestHeaders(jwt));
}

Expand Down
2 changes: 1 addition & 1 deletion Gotrue/Interfaces/IGotrueAdminClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface IGotrueAdminClient<TUser> : IGettableHeaders
/// Creates a user using the admin key (not the anonymous key).
/// Used in trusted server environments, not client apps.
/// </summary>
Task<bool> DeleteUser(string uid);
Task<bool> DeleteUser(string uid, bool shouldSoftDelete = false);

/// <summary>
/// Gets a user from a user's JWT. This is using the GoTrue server to validate a user's JWT.
Expand Down
2 changes: 1 addition & 1 deletion Gotrue/Interfaces/IGotrueApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IGotrueApi<TUser, TSession> : IGettableHeaders
where TSession : Session
{
Task<TUser?> CreateUser(string jwt, AdminUserAttributes? attributes = null);
Task<BaseResponse> DeleteUser(string uid, string jwt);
Task<BaseResponse> DeleteUser(string jwt, string uid, bool shouldSoftDelete = false);
Task<TUser?> GetUser(string jwt);
Task<TUser?> GetUserById(string jwt, string userId);
Task<BaseResponse> InviteUserByEmail(string email, string jwt, InviteUserByEmailOptions? options = null);
Expand Down
5 changes: 3 additions & 2 deletions Gotrue/Interfaces/IGotrueStatelessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ public interface IGotrueStatelessClient<TUser, TSession>
/// <summary>
/// Deletes a User.
/// </summary>
/// <param name="uid"></param>
/// <param name="serviceRoleToken">this token needs role 'supabase_admin' or 'service_role'</param>
/// <param name="options"></param>
/// <param name="uid"></param>
/// <param name="shouldSoftDelete">If true, then the user will be soft-deleted. Defaults to false.</param>
/// <returns></returns>
Task<bool> DeleteUser(string uid, string serviceRoleToken, StatelessClientOptions options);
Task<bool> DeleteUser(string serviceRoleToken, StatelessClientOptions options, string uid, bool shouldSoftDelete = false);

/// <summary>
/// Logs in an existing user via a third-party provider.
Expand Down
4 changes: 2 additions & 2 deletions Gotrue/StatelessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ public async Task<bool> ResetPasswordForEmail(string email, StatelessClientOptio
}

/// <inheritdoc />
public async Task<bool> DeleteUser(string uid, string serviceRoleToken, StatelessClientOptions options)
public async Task<bool> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion GotrueTests/StatelessClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down