[GH-ISSUE #1046] Clean Out Expired Verifications from Database #8566

Closed
opened 2026-04-13 03:41:05 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @daveycodez on GitHub (Dec 28, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1046

Is this suited for github?

  • Yes, this is suited for github

No response

Describe the solution you'd like

It looks like the verifications table doesn't get cleaned up automatically, would be great to have a DELETE where expired query applied to it at some point during verification process. I imagine this table can get pretty overflowing with a large user base.

Describe alternatives you've considered

custom cronjob

Additional context

No response

Originally created by @daveycodez on GitHub (Dec 28, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1046 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. _No response_ ### Describe the solution you'd like It looks like the verifications table doesn't get cleaned up automatically, would be great to have a DELETE where expired query applied to it at some point during verification process. I imagine this table can get pretty overflowing with a large user base. ### Describe alternatives you've considered custom cronjob ### Additional context _No response_
GiteaMirror added the stalelocked labels 2026-04-13 03:41:05 -05:00
Author
Owner

@daveycodez commented on GitHub (Dec 28, 2024):

Would also be good to have some sort of method for deleting old anonymous users, maybe allow a setting to delete anonymous users X days after creation

<!-- gh-comment-id:2564142620 --> @daveycodez commented on GitHub (Dec 28, 2024): Would also be good to have some sort of method for deleting old anonymous users, maybe allow a setting to delete anonymous users X days after creation
Author
Owner

@Bekacru commented on GitHub (Dec 28, 2024):

you'll need to run some kind of job but most users still use serverless, so providing something out of the box might be difficult. But, a cleanup helper function would be a good addition.

<!-- gh-comment-id:2564247004 --> @Bekacru commented on GitHub (Dec 28, 2024): you'll need to run some kind of job but most users still use serverless, so providing something out of the box might be difficult. But, a cleanup helper function would be a good addition.
Author
Owner

@daveycodez commented on GitHub (Dec 28, 2024):

Is there a reason not to just run the DELETE from verifications where expired query before inserting into verifications? I get it adds an extra query for verifications but that shouldn't be too much noticeable slowdown since verifications are a more rare operation. I assume we are already cleaning up sessions that expire in a similar manner? I think I'm OK with a little extra latency on verifications in order to not run a cron

<!-- gh-comment-id:2564277328 --> @daveycodez commented on GitHub (Dec 28, 2024): Is there a reason not to just run the DELETE from verifications where expired query before inserting into verifications? I get it adds an extra query for verifications but that shouldn't be too much noticeable slowdown since verifications are a more rare operation. I assume we are already cleaning up sessions that expire in a similar manner? I think I'm OK with a little extra latency on verifications in order to not run a cron
Author
Owner

@Bekacru commented on GitHub (Dec 28, 2024):

We do run a delete when a value is expired upon verification, but we don't delete all verifications only that specific one. But I think it could be a good idea to delete all verifications that has expired.

<!-- gh-comment-id:2564296920 --> @Bekacru commented on GitHub (Dec 28, 2024): We do run a delete when a value is expired upon verification, but we don't delete all verifications only that specific one. But I think it could be a good idea to delete all verifications that has expired.
Author
Owner

@dosubot[bot] commented on GitHub (Jun 13, 2025):

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

Issue Summary:

  • You proposed a feature to automatically delete expired verifications to prevent database overcrowding.
  • Suggested method for deleting old anonymous users after a set period.
  • @Bekacru highlighted challenges in serverless environments but supported a cleanup helper function.
  • Discussion on running DELETE queries for expired verifications during the verification process.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If no updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:2970840599 --> @dosubot[bot] commented on GitHub (Jun 13, 2025): Hi, @daveycodez. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - You proposed a feature to automatically delete expired verifications to prevent database overcrowding. - Suggested method for deleting old anonymous users after a set period. - @Bekacru highlighted challenges in serverless environments but supported a cleanup helper function. - Discussion on running DELETE queries for expired verifications during the verification process. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If no updates are provided, the 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#8566