[PR #5280] feat(session): add option to mark sessions as inactive instead of deleting #31500

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5280
Author: @Blackmamoth
Created: 10/13/2025
Status: 🔄 Open

Base: nextHead: feat/delete-session-on-signout


📝 Commits (10+)

  • 403b1e0 feat: add new types and initial logic for session deletion on sign out
  • e10fa15 fix: refactor to use 'options' directly, update 'getAuthTables' logic, and add tests for new fields
  • f3d93b7 Merge branch 'canary' into feat/delete-session-on-signout
  • 65b83de fix: provide default value for invalidatedAt field and write tests for deleteSessionOnSignOut configurations
  • 1931b35 test: update existing logic for findSessions and listSessions and added relevant test cases
  • eabcd2f chore: code cleanup in createSession method
  • e87ef77 docs: add deleteSessionOnSignOut in session options
  • 1f8c241 Merge branch 'canary' into feat/delete-session-on-signout
  • 6ad3d03 Merge branch 'canary' into feat/delete-session-on-signout
  • 62fb79c fix: remove isActive and invalidatedAt fields from core schema, add SessionWithSoftDelete interface to include isActive and invalidatedAt type

📊 Changes

7 files changed (+502 additions, -35 deletions)

View changed files

📝 docs/content/docs/reference/options.mdx (+7 -2)
📝 packages/better-auth/src/db/get-tables.test.ts (+37 -0)
📝 packages/better-auth/src/db/get-tables.ts (+22 -0)
📝 packages/better-auth/src/db/internal-adapter.test.ts (+272 -0)
📝 packages/better-auth/src/db/internal-adapter.ts (+142 -33)
📝 packages/better-auth/src/types/models.ts (+5 -0)
📝 packages/core/src/types/init-options.ts (+17 -0)

📄 Description

Summary

Adds a configuration option to mark sessions as inactive (isActive) or timestamped (invalidatedAt) instead of deleting them on sign-out, allowing session history to be preserved.

Changes

  • Added deleteSessionOnSignOut option under session
  • Updated session schema to include isActive or invalidatedAt based on config
  • Modified sign-out logic to update the field instead of deleting when enabled
  • Added tests and updated documentation

Context

This change addresses the open issue where signing out or revoking a session deletes session records entirely, making it hard to track session history. The new option provides a soft-delete alternative.

Closes #4518

Breaking Changes

  • Non-breaking by default
  • Enabling the feature requires adding isActive or invalidatedAt to the session table

Tests

  • Verified schema generation and sign-out behavior
  • Default deletion still works
  • All tests passing

Summary by cubic

Adds a session option to soft-delete on sign-out by marking sessions inactive or timestamping invalidation instead of deleting. Preserves session history while keeping inactive sessions out of lookups.

  • New Features

    • Added session.deleteSessionOnSignOut with enabled (default: true) and timestamp (default: false).
    • When enabled=false, createSession sets isActive=true or invalidatedAt=null; deleteSession/deleteSessions flip isActive=false or set invalidatedAt=now.
    • findSession, listSessions, and findSessions skip inactive/invalidated sessions.
    • Conditionally add isActive or invalidatedAt to the session schema when enabled=false.
    • Updated docs and tests.
  • Migration

    • If using soft delete (enabled=false), add isActive (boolean) or invalidatedAt (date) to the session table. No changes needed if you keep default deletion.

Written for commit 25f2176f8c. Summary will update automatically 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/5280 **Author:** [@Blackmamoth](https://github.com/Blackmamoth) **Created:** 10/13/2025 **Status:** 🔄 Open **Base:** `next` ← **Head:** `feat/delete-session-on-signout` --- ### 📝 Commits (10+) - [`403b1e0`](https://github.com/better-auth/better-auth/commit/403b1e0bddb03e4c13a8f7b254f77d45b3e82f47) feat: add new types and initial logic for session deletion on sign out - [`e10fa15`](https://github.com/better-auth/better-auth/commit/e10fa15da3e818c91b143f4faa9c51195503e1d2) fix: refactor to use 'options' directly, update 'getAuthTables' logic, and add tests for new fields - [`f3d93b7`](https://github.com/better-auth/better-auth/commit/f3d93b729e3eeda57c2a77d8a4bc46bb222f4b96) Merge branch 'canary' into feat/delete-session-on-signout - [`65b83de`](https://github.com/better-auth/better-auth/commit/65b83de9c1a1c0e5ba61f7f5cfbeffb35adc357b) fix: provide default value for invalidatedAt field and write tests for deleteSessionOnSignOut configurations - [`1931b35`](https://github.com/better-auth/better-auth/commit/1931b3502c5852874fa0feabae3300565c35f6cc) test: update existing logic for findSessions and listSessions and added relevant test cases - [`eabcd2f`](https://github.com/better-auth/better-auth/commit/eabcd2f2f9ba6724d29e2f45ce4981b32fce359a) chore: code cleanup in createSession method - [`e87ef77`](https://github.com/better-auth/better-auth/commit/e87ef777ffa9de751ea68f056f00634e7417ce2f) docs: add deleteSessionOnSignOut in session options - [`1f8c241`](https://github.com/better-auth/better-auth/commit/1f8c241cdc5f3b1778c46fb6cbc3b1fc54d290fa) Merge branch 'canary' into feat/delete-session-on-signout - [`6ad3d03`](https://github.com/better-auth/better-auth/commit/6ad3d031c7c49eeca75d09f38bc5f6dce6ed9ae8) Merge branch 'canary' into feat/delete-session-on-signout - [`62fb79c`](https://github.com/better-auth/better-auth/commit/62fb79cc4e461a1aebccebb74dd823d73564bf46) fix: remove isActive and invalidatedAt fields from core schema, add SessionWithSoftDelete interface to include isActive and invalidatedAt type ### 📊 Changes **7 files changed** (+502 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/reference/options.mdx` (+7 -2) 📝 `packages/better-auth/src/db/get-tables.test.ts` (+37 -0) 📝 `packages/better-auth/src/db/get-tables.ts` (+22 -0) 📝 `packages/better-auth/src/db/internal-adapter.test.ts` (+272 -0) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+142 -33) 📝 `packages/better-auth/src/types/models.ts` (+5 -0) 📝 `packages/core/src/types/init-options.ts` (+17 -0) </details> ### 📄 Description ### Summary Adds a configuration option to mark sessions as inactive (`isActive`) or timestamped (`invalidatedAt`) instead of deleting them on sign-out, allowing session history to be preserved. ### Changes - Added `deleteSessionOnSignOut` option under `session` - Updated session schema to include `isActive` or `invalidatedAt` based on config - Modified sign-out logic to update the field instead of deleting when enabled - Added tests and updated documentation ### Context This change addresses the open issue where signing out or revoking a session deletes session records entirely, making it hard to track session history. The new option provides a soft-delete alternative. Closes #4518 ### Breaking Changes - Non-breaking by default - Enabling the feature requires adding `isActive` or `invalidatedAt` to the session table ### Tests - Verified schema generation and sign-out behavior - Default deletion still works - All tests passing <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds a session option to soft-delete on sign-out by marking sessions inactive or timestamping invalidation instead of deleting. Preserves session history while keeping inactive sessions out of lookups. - **New Features** - Added session.deleteSessionOnSignOut with enabled (default: true) and timestamp (default: false). - When enabled=false, createSession sets isActive=true or invalidatedAt=null; deleteSession/deleteSessions flip isActive=false or set invalidatedAt=now. - findSession, listSessions, and findSessions skip inactive/invalidated sessions. - Conditionally add isActive or invalidatedAt to the session schema when enabled=false. - Updated docs and tests. - **Migration** - If using soft delete (enabled=false), add isActive (boolean) or invalidatedAt (date) to the session table. No changes needed if you keep default deletion. <sup>Written for commit 25f2176f8c3fb78c36256b37729cd9157e11a9bc. Summary will update automatically 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 22:23:47 -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#31500