[GH-ISSUE #1280] Delete stale session #17304

Closed
opened 2026-04-15 15:24:27 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @dassaswat on GitHub (Jan 25, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1280

To Reproduce

  1. Signin
  2. Open Devtools and delete the cookies. (DO NOT SIGNOUT)
  3. Now refresh the page . You are logged out. (obv)
  4. If we go checkout the db, the session still exits. Set the expirtAT to the current timestamp (to expire it.)
  5. Now login, a new session gets created. But the previous session still exists even though we expired it. (A zombie session)

Current vs. Expected behavior

If the user manually clear the cookies that includes the session token it never gets deleted from the db. The session data exists in the db even after the session has expired.

What version of Better Auth are you using?

1.1.14

Provide environment information

- OS: [macos]
- Browser: [chrome, arc, safari]

Which area(s) are affected? (Select all that apply)

Backend

Originally created by @dassaswat on GitHub (Jan 25, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1280 ### To Reproduce 1. Signin 2. Open Devtools and delete the cookies. (DO NOT SIGNOUT) 3. Now refresh the page . You are logged out. (obv) 4. If we go checkout the db, the session still exits. Set the expirtAT to the current timestamp (to expire it.) 5. Now login, a new session gets created. But the previous session still exists even though we expired it. (A zombie session) ### Current vs. Expected behavior If the user manually clear the cookies that includes the session token it never gets deleted from the db. The session data exists in the db even after the session has expired. ### What version of Better Auth are you using? 1.1.14 ### Provide environment information ```bash - OS: [macos] - Browser: [chrome, arc, safari] ``` ### Which area(s) are affected? (Select all that apply) Backend
GiteaMirror added the lockedbug labels 2026-04-15 15:24:28 -05:00
Author
Owner

@moshetanzer commented on GitHub (Mar 24, 2025):

Hey,

This obviously occurs. I would suggest you create a cron job to delete all expired sessions.

Don't think this is in the scope of this libary and should be implemented in userland, unless we create a "delete all expired sesssions" util - @Bekacru

<!-- gh-comment-id:2746910082 --> @moshetanzer commented on GitHub (Mar 24, 2025): Hey, This obviously occurs. I would suggest you create a cron job to delete all expired sessions. Don't think this is in the scope of this libary and should be implemented in userland, unless we create a "delete all expired sesssions" util - @Bekacru
Author
Owner

@pradel commented on GitHub (Apr 11, 2025):

@moshetanzer would be really useful if the lib could expose the util and let the cron implementation to the user

<!-- gh-comment-id:2796773678 --> @pradel commented on GitHub (Apr 11, 2025): @moshetanzer would be really useful if the lib could expose the util and let the cron implementation to the user
Author
Owner

@Kinfe123 commented on GitHub (Apr 14, 2025):

Again, this isn't really within the scope of the library—but since there are other use cases, like security auditing and a bunch of other niche scenarios where keeping the session might be useful, we figured it’s worth mentioning. That said, this kind of thing is better left to the user to implement in their own way, if they actually need it

<!-- gh-comment-id:2801083972 --> @Kinfe123 commented on GitHub (Apr 14, 2025): Again, this isn't really within the scope of the library—but since there are other use cases, like security auditing and a bunch of other niche scenarios where keeping the session might be useful, we figured it’s worth mentioning. That said, this kind of thing is better left to the user to implement in their own way, if they actually need it
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17304