[PR #3413] [MERGED] fix(api-key): API Keys with expiresAt not null #4806

Closed
opened 2026-03-13 12:00:27 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3413
Author: @reslear
Created: 7/16/2025
Status: Merged
Merged: 7/17/2025
Merged by: @Bekacru

Base: mainHead: patch-13


📝 Commits (3)

📊 Changes

1 file changed (+5 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/plugins/api-key/routes/index.ts (+5 -0)

📄 Description

The deleteAllExpiredApiKeys function in the apiKey plugin deletes API keys where expiresAt is null, despite these keys being intended as non-expiring.

This occurs because the deleteMany query does not explicitly exclude null values in the expiresAt condition.

This leads to unexpected key deletions, affecting keys like

{ "_id": "6876ba254c23e91c05c9e95b", "expiresAt": null }

this is Mongodb case not same like sql

cc @ping-maxwell can we add test for this case?


Summary by cubic

Fixed an issue where non-expiring API keys (with expiresAt set to null) were being deleted by mistake.

  • Bug Fixes
    • Updated the expired API key deletion logic to exclude keys with expiresAt set to null.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3413 **Author:** [@reslear](https://github.com/reslear) **Created:** 7/16/2025 **Status:** ✅ Merged **Merged:** 7/17/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `patch-13` --- ### 📝 Commits (3) - [`8fefd42`](https://github.com/better-auth/better-auth/commit/8fefd426349d71db8ff5429db8778e710736c1b0) fix(api-key): API Keys with expiresAt not null - [`776fd6b`](https://github.com/better-auth/better-auth/commit/776fd6b19aa2ef70951624f9ee15455f935527eb) Update index.ts - [`f4a8407`](https://github.com/better-auth/better-auth/commit/f4a840761e5fede36753256d1f9811603dd4b2d2) chore: lint ### 📊 Changes **1 file changed** (+5 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/api-key/routes/index.ts` (+5 -0) </details> ### 📄 Description The `deleteAllExpiredApiKeys` function in the apiKey plugin deletes API keys where `expiresAt` is `null`, despite these keys being intended as non-expiring. This occurs because the deleteMany query does not explicitly exclude null values in the expiresAt condition. This leads to unexpected key deletions, affecting keys like ```json { "_id": "6876ba254c23e91c05c9e95b", "expiresAt": null } ``` this is Mongodb case not same like sql cc @ping-maxwell can we add test for this case? <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixed an issue where non-expiring API keys (with expiresAt set to null) were being deleted by mistake. - **Bug Fixes** - Updated the expired API key deletion logic to exclude keys with expiresAt set to null. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:00:27 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#4806