[GH-ISSUE #2669] Handle soft delete for user #9293

Closed
opened 2026-04-13 04:43:14 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @MarkLee425 on GitHub (May 16, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2669

Is this suited for github?

  • Yes, this is suited for github

Currently there is only hard delete in the solution.

Describe the solution you'd like

Add a soft delete option, which will have a function for updating the fields (e.g. revoked_at: current_timestamp / isRevoked: true)

Describe alternatives you've considered

Currently the alternatives is to turn off hard delete option, and manually update it through updateUser / updateAccount etc.

Additional context

No response

Originally created by @MarkLee425 on GitHub (May 16, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2669 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently there is only hard delete in the solution. ### Describe the solution you'd like Add a soft delete option, which will have a function for updating the fields (e.g. revoked_at: current_timestamp / isRevoked: true) ### Describe alternatives you've considered Currently the alternatives is to turn off hard delete option, and manually update it through updateUser / updateAccount etc. ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:43:14 -05:00
Author
Owner

@MarkLee425 commented on GitHub (May 31, 2025):

Just found it impossible to add the sign in and sign up logic to check the revoked_at is null or not...

<!-- gh-comment-id:2925047892 --> @MarkLee425 commented on GitHub (May 31, 2025): Just found it impossible to add the sign in and sign up logic to check the revoked_at is null or not...
Author
Owner

@MarkLee425 commented on GitHub (May 31, 2025):

My recommended solution is to change the current deleteUser property logic.

Add a "mode" option to decide the mode is "hard delete" or "soft delete". Keep all the existing logic into hard delete mode.

SOFT DELETE:
User should have added their additional fields already and deleteUser can have 3 options, signUpCriteria, signInCriteria and onDeleteData.

signUpCriteria: add criteria to sign up (i.e. check for user that revoked_at IS NULL)

signInCriteria: same logic as signUpCriteria

onDeleteData: this should be updated for the specific user. i.e. { revoked_at: }

The logic will be update the onDeleteData to the user. Then destroy the session and cookies, and then redirect to the sign in page or redirectUrl.

Let me know if there are better solutions...

<!-- gh-comment-id:2925076463 --> @MarkLee425 commented on GitHub (May 31, 2025): My recommended solution is to change the current deleteUser property logic. Add a "mode" option to decide the mode is "hard delete" or "soft delete". Keep all the existing logic into hard delete mode. SOFT DELETE: User should have added their additional fields already and deleteUser can have 3 options, signUpCriteria, signInCriteria and onDeleteData. signUpCriteria: add criteria to sign up (i.e. check for user that revoked_at IS NULL) signInCriteria: same logic as signUpCriteria onDeleteData: this should be updated for the specific user. i.e. { revoked_at: <currentTimestamp> } The logic will be update the onDeleteData to the user. Then destroy the session and cookies, and then redirect to the sign in page or redirectUrl. Let me know if there are better solutions...
Author
Owner

@maelp commented on GitHub (Sep 5, 2025):

Would be interested in this too, @Kinfe123 why don't you think this should be added? In general all my resources have linked to userId (eg comments, created items, etc), so if I delete a user, all those will be invalid (because I'm using user_id: id.references(users.id)) so I'd need a soft-delete for this

<!-- gh-comment-id:3257563378 --> @maelp commented on GitHub (Sep 5, 2025): Would be interested in this too, @Kinfe123 why don't you think this should be added? In general all my resources have linked to userId (eg comments, created items, etc), so if I delete a user, all those will be invalid (because I'm using `user_id: id.references(users.id)`) so I'd need a soft-delete for this
Author
Owner

@mortenson commented on GitHub (Mar 11, 2026):

I ended up allow-listing better auth routes to not allow access to deletion, then added these hooks for "peace of mind":

  databaseHooks: {
    account: {
      delete: {
        before: () => {
          throw new Error("Unreachable case: account.delete");
        },
      },
    },
    session: {
      delete: {
        before: () => {
          throw new Error("Unreachable case: session.delete");
        },
      },
    },
    user: {
      delete: {
        before: () => {
          throw new Error("Unreachable case: user.delete");
        },
      },
    },
  },

You can also return false from the before hook(s) and implement soft delete yourself. For instance, I did this with sessions to expire the session immediately instead of deleting it.

<!-- gh-comment-id:4039789382 --> @mortenson commented on GitHub (Mar 11, 2026): I ended up allow-listing better auth routes to not allow access to deletion, then added these hooks for "peace of mind": ``` databaseHooks: { account: { delete: { before: () => { throw new Error("Unreachable case: account.delete"); }, }, }, session: { delete: { before: () => { throw new Error("Unreachable case: session.delete"); }, }, }, user: { delete: { before: () => { throw new Error("Unreachable case: user.delete"); }, }, }, }, ``` You can also return false from the before hook(s) and implement soft delete yourself. For instance, I did this with sessions to expire the session immediately instead of deleting it.
Author
Owner

@github-actions[bot] commented on GitHub (Apr 1, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4166555386 --> @github-actions[bot] commented on GitHub (Apr 1, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9293