[PR #7285] [MERGED] fix(session): prevent duplicate tokens in active sessions list #32798

Closed
opened 2026-04-17 23:31:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7285
Author: @theonlypal
Created: 1/12/2026
Status: Merged
Merged: 1/12/2026
Merged by: @himself65

Base: canaryHead: fix/duplicate-sessions-secondary-storage


📝 Commits (5)

  • e1e7be5 fix(session): prevent duplicate tokens in active sessions list
  • 0ee66aa test: add test case for duplicate session deduplication
  • 1605802 fix: prevent duplicate sessions in listSessions
  • 1dbb272 Merge branch 'canary' into fix/duplicate-sessions-secondary-storage
  • d262557 Merge branch 'canary' into fix/duplicate-sessions-secondary-storage

📊 Changes

2 files changed (+102 additions, -30 deletions)

View changed files

📝 packages/better-auth/src/db/internal-adapter.test.ts (+71 -0)
📝 packages/better-auth/src/db/internal-adapter.ts (+31 -30)

📄 Description

Closes #7281

When using secondary storage, the active sessions list could contain duplicate tokens if the same session was added multiple times. This caused listSessions() to return duplicate entries.

Filter out existing token before adding to prevent duplicates.


Summary by cubic

Fixes duplicate tokens in the active sessions list when secondary storage is enabled. We now filter out existing tokens when writing and deduplicate in listSessions(), ensuring unique sessions with correct expiration ordering.

Written for commit d262557e05. Summary will update on new commits.


🔄 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/7285 **Author:** [@theonlypal](https://github.com/theonlypal) **Created:** 1/12/2026 **Status:** ✅ Merged **Merged:** 1/12/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/duplicate-sessions-secondary-storage` --- ### 📝 Commits (5) - [`e1e7be5`](https://github.com/better-auth/better-auth/commit/e1e7be56135eadf5e2163325162b55b283b721d7) fix(session): prevent duplicate tokens in active sessions list - [`0ee66aa`](https://github.com/better-auth/better-auth/commit/0ee66aae794ba9dae5cc83dda89a0c90e53c411a) test: add test case for duplicate session deduplication - [`1605802`](https://github.com/better-auth/better-auth/commit/1605802873cccbf32bab99c78cb88cd861f206a9) fix: prevent duplicate sessions in listSessions - [`1dbb272`](https://github.com/better-auth/better-auth/commit/1dbb272393db80146cd0a6348c4b20e861ed85cc) Merge branch 'canary' into fix/duplicate-sessions-secondary-storage - [`d262557`](https://github.com/better-auth/better-auth/commit/d262557e054919252d919cc0ff0f5679c3dc70db) Merge branch 'canary' into fix/duplicate-sessions-secondary-storage ### 📊 Changes **2 files changed** (+102 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/internal-adapter.test.ts` (+71 -0) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+31 -30) </details> ### 📄 Description Closes #7281 When using secondary storage, the active sessions list could contain duplicate tokens if the same session was added multiple times. This caused `listSessions()` to return duplicate entries. Filter out existing token before adding to prevent duplicates. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes duplicate tokens in the active sessions list when secondary storage is enabled. We now filter out existing tokens when writing and deduplicate in listSessions(), ensuring unique sessions with correct expiration ordering. <sup>Written for commit d262557e054919252d919cc0ff0f5679c3dc70db. Summary will update on new commits.</sup> <!-- 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-04-17 23:31:46 -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#32798