[PR #6155] [CLOSED] feat(multi-session): use database for multi session #6487

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6155
Author: @Bekacru
Created: 11/21/2025
Status: Closed

Base: canaryHead: feat/multi-session


📝 Commits (2)

  • 443a622 feat(multi-session): use database for multi session
  • 0bbe026 docs

📊 Changes

3 files changed (+290 additions, -336 deletions)

View changed files

📝 docs/content/docs/plugins/multi-session.mdx (+33 -6)
📝 packages/better-auth/src/plugins/multi-session/index.ts (+183 -181)
📝 packages/better-auth/src/plugins/multi-session/multi-session.test.ts (+74 -149)

📄 Description

Multi-session previously relied on cookies. But cookie-based multi-session comes with a lot of limitations. It’s better to introduce a multi-session approach that relies on server-side state instead


Summary by cubic

Switch multi-session from cookie-based to server-side, device-bound sessions. Improves security, simplifies logic, and enforces per-device session limits.

  • New Features

    • Add a signed device_id cookie (configurable name/options) to bind sessions to a device.
    • Database hook on session creation sets deviceId and prunes oldest sessions when exceeding the maximum (default 5).
    • List device sessions now queries by deviceId and returns session + user data.
    • Set active validates device ownership (deviceId) before switching.
    • Revoke deletes the session and clears the active cookie if it was the current session.
  • Migration

    • Add deviceId (string, optional, input: false) to the session schema.
    • Remove reliance on “_multi-” session cookies; multi-session is now database-driven.
    • Existing client API calls (list/setActive/revoke) continue to work; cookie handling is internal.

Written for commit 0bbe0266aa. 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/6155 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 11/21/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/multi-session` --- ### 📝 Commits (2) - [`443a622`](https://github.com/better-auth/better-auth/commit/443a622f55b20a328f95c6a5838bd07342993eca) feat(multi-session): use database for multi session - [`0bbe026`](https://github.com/better-auth/better-auth/commit/0bbe0266aaff82505642c54f1d0b65f0b8442513) docs ### 📊 Changes **3 files changed** (+290 additions, -336 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/multi-session.mdx` (+33 -6) 📝 `packages/better-auth/src/plugins/multi-session/index.ts` (+183 -181) 📝 `packages/better-auth/src/plugins/multi-session/multi-session.test.ts` (+74 -149) </details> ### 📄 Description Multi-session previously relied on cookies. But cookie-based multi-session comes with a lot of limitations. It’s better to introduce a multi-session approach that relies on server-side state instead <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Switch multi-session from cookie-based to server-side, device-bound sessions. Improves security, simplifies logic, and enforces per-device session limits. - **New Features** - Add a signed device_id cookie (configurable name/options) to bind sessions to a device. - Database hook on session creation sets deviceId and prunes oldest sessions when exceeding the maximum (default 5). - List device sessions now queries by deviceId and returns session + user data. - Set active validates device ownership (deviceId) before switching. - Revoke deletes the session and clears the active cookie if it was the current session. - **Migration** - Add deviceId (string, optional, input: false) to the session schema. - Remove reliance on “_multi-” session cookies; multi-session is now database-driven. - Existing client API calls (list/setActive/revoke) continue to work; cookie handling is internal. <sup>Written for commit 0bbe0266aaff82505642c54f1d0b65f0b8442513. 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-03-13 13:00:57 -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#6487