[GH-ISSUE #6224] Bulk revocation of user sessions #19083

Closed
opened 2026-04-15 17:52:29 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @maelp on GitHub (Nov 22, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6224

Is this suited for github?

  • Yes, this is suited for github

Is your feature request related to a problem? Please describe.

Hi, I'd like to find a way to revoke all existing sessions for a batch of users. I have a list of userIds, and I'd like to revoke all corresponding sessions.

I see that the admin plugin has a revokeAllUserSessions but this means I would have to iterate through the list and revoke them one by one.

Also, the admin plugin, even called on the server, requires the headers and cookie in order to know who calls the method. But I'd like my backend to have this feature that's accessible even to some specific users who don't have the "admin" role on the admin plugin

Is there a way to expose a method to revoke user sessions ?

I'd like to access auth.context.internalAdapter.deleteSessions but from my own code, is there anything like that that's possible?

Describe the solution you'd like

I'd like a backend API that doesn't require headers or whatever, and which can just take a list of users, and revoke their sessions.

Technically I could try to just delete all the sessions in the database sessions table, but this would fail if the BetterAuth instance uses secondary storage to store sessions

Describe alternatives you've considered

Iterate through the users using the admin plugin, but this requires the user doing the action to have "admin" role, however in my particular case I'd like to allow some other users to do this specific action

Additional context

No response

Originally created by @maelp on GitHub (Nov 22, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6224 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Hi, I'd like to find a way to revoke all existing sessions for a batch of users. I have a list of userIds, and I'd like to revoke all corresponding sessions. I see that the admin plugin has a revokeAllUserSessions but this means I would have to iterate through the list and revoke them one by one. Also, the admin plugin, even called on the server, requires the headers and cookie in order to know who calls the method. But I'd like my backend to have this feature that's accessible even to some specific users who don't have the "admin" role on the admin plugin Is there a way to expose a method to revoke user sessions ? I'd like to access auth.context.internalAdapter.deleteSessions but from my own code, is there anything like that that's possible? ### Describe the solution you'd like I'd like a backend API that doesn't require headers or whatever, and which can just take a list of users, and revoke their sessions. Technically I could try to just delete all the sessions in the database sessions table, but this would fail if the BetterAuth instance uses secondary storage to store sessions ### Describe alternatives you've considered Iterate through the users using the admin plugin, but this requires the user doing the action to have "admin" role, however in my particular case I'd like to allow some other users to do this specific action ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-15 17:52:29 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 22, 2025):

Hi there, thanks for reaching out with your query!

Currently, Better Auth doesn’t expose a public method for bulk revocation of sessions that bypasses the header and admin role requirements. The admin plugin’s revokeAllUserSessions requires a valid header for authentication, as it’s designed to operate within a secure, defined user context [1]. One approach is to build a custom backend endpoint that calls the internal adapter’s deleteSessions function directly using your list of user IDs. However, please note that if your Better Auth instance uses secondary storage for sessions, you’ll need to ensure that your custom logic properly handles all storage layers to fully revoke those sessions [2].

Would you be open to discussing potential workarounds, or even tracking a feature enhancement that allows bulk revocation without the admin header requirement? tag @better-auth-agent if you would like an answer from the Agent

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3567161051 --> @better-auth-agent[bot] commented on GitHub (Nov 22, 2025): Hi there, thanks for reaching out with your query! Currently, Better Auth doesn’t expose a public method for bulk revocation of sessions that bypasses the header and admin role requirements. The admin plugin’s revokeAllUserSessions requires a valid header for authentication, as it’s designed to operate within a secure, defined user context [[1]](https://www.better-auth.com/docs/reference/contributing). One approach is to build a custom backend endpoint that calls the internal adapter’s deleteSessions function directly using your list of user IDs. However, please note that if your Better Auth instance uses secondary storage for sessions, you’ll need to ensure that your custom logic properly handles all storage layers to fully revoke those sessions [[2]](https://github.com/better-auth/better-auth/issues/4512). Would you be open to discussing potential workarounds, or even tracking a feature enhancement that allows bulk revocation without the admin header requirement? tag @better-auth-agent if you would like an answer from the Agent <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@maelp commented on GitHub (Nov 22, 2025):

To add some context, my particular use-case is this:

  • I have a notion of "organization" which is different from BetterAuth organization (as the BetterAuth organizations wouldn't fit exactly my purpose)
  • my users can belong to one or more of those organizations
  • when I deactivate an organization, I want to terminate all the existing sessions of the users
<!-- gh-comment-id:3567163313 --> @maelp commented on GitHub (Nov 22, 2025): To add some context, my particular use-case is this: - I have a notion of "organization" which is different from BetterAuth organization (as the BetterAuth organizations wouldn't fit exactly my purpose) - my users can belong to one or more of those organizations - when I deactivate an organization, I want to terminate all the existing sessions of the users
Author
Owner

@dosubot[bot] commented on GitHub (Feb 21, 2026):

Hi, @maelp. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested a backend API feature to revoke all sessions for multiple users without requiring admin role or headers.
  • Current admin plugin method revokes sessions individually and requires admin privileges.
  • better-auth-agent noted no public bulk revocation method exists without admin authentication and suggested a custom backend endpoint using internal adapter functions.
  • You clarified your use case involves deactivating a custom "organization" concept and terminating all sessions for its users.
  • The discussion included potential feature enhancement tracking for this capability.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3939031859 --> @dosubot[bot] commented on GitHub (Feb 21, 2026): Hi, @maelp. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested a backend API feature to revoke all sessions for multiple users without requiring admin role or headers. - Current admin plugin method revokes sessions individually and requires admin privileges. - better-auth-agent noted no public bulk revocation method exists without admin authentication and suggested a custom backend endpoint using internal adapter functions. - You clarified your use case involves deactivating a custom "organization" concept and terminating all sessions for its users. - The discussion included potential feature enhancement tracking for this capability. **Next Steps:** - Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open. - Otherwise, this issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19083