[PR #3296] [CLOSED] Fix: session id mapping #30343

Closed
opened 2026-04-17 21:27:47 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3296
Author: @tinkerer-shubh
Created: 7/8/2025
Status: Closed

Base: mainHead: fix-session-id-mapping


📝 Commits (2)

  • f9dcfc4 fix: session id↔token mapping
  • 306d616 fix(session): use logical OR to avoid empty token column mapping

📊 Changes

2 files changed (+27 additions, -3 deletions)

View changed files

📝 packages/better-auth/src/db/get-tables.ts (+14 -1)
📝 packages/better-auth/src/db/internal-adapter.ts (+13 -2)

📄 Description

closes https://github.com/better-auth/better-auth/issues/3281

  1. File: packages/better-auth/src/db/get-tables.ts

    • Introduces a new SessionFieldOverrides interface to clarify which session fields can be overridden (token and id).
    • Updates the logic for determining the database column used for the session token/id. It now prefers a custom token field (if mapped), otherwise falls back to id, and finally defaults to "token".
    • This change avoids unsafe type casts and ensures the correct field is used for session token mapping.
  2. File: packages/better-auth/src/db/internal-adapter.ts

    • Refactors session creation logic:
      • Generates a unique session ID (sessionId).
      • If the user has mapped a custom token column, a separate random value is generated for the token; otherwise, the token simply uses the session ID.
      • This prevents accidentally writing two different values to the same database column if token falls back to id.
    • Updates session data construction to use the new sessionId and tokenValue logic.

🔄 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/3296 **Author:** [@tinkerer-shubh](https://github.com/tinkerer-shubh) **Created:** 7/8/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix-session-id-mapping` --- ### 📝 Commits (2) - [`f9dcfc4`](https://github.com/better-auth/better-auth/commit/f9dcfc442d925601ebc34dd697b4355af00717b8) fix: session id↔token mapping - [`306d616`](https://github.com/better-auth/better-auth/commit/306d616c0545f390deb44a817cee20121a164d55) fix(session): use logical OR to avoid empty token column mapping ### 📊 Changes **2 files changed** (+27 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/get-tables.ts` (+14 -1) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+13 -2) </details> ### 📄 Description closes https://github.com/better-auth/better-auth/issues/3281 1. **File:** `packages/better-auth/src/db/get-tables.ts` - Introduces a new `SessionFieldOverrides` interface to clarify which session fields can be overridden (`token` and `id`). - Updates the logic for determining the database column used for the session token/id. It now prefers a custom `token` field (if mapped), otherwise falls back to `id`, and finally defaults to `"token"`. - This change avoids unsafe type casts and ensures the correct field is used for session token mapping. 2. **File:** `packages/better-auth/src/db/internal-adapter.ts` - Refactors session creation logic: - Generates a unique session ID (`sessionId`). - If the user has mapped a custom `token` column, a separate random value is generated for the token; otherwise, the token simply uses the session ID. - This prevents accidentally writing two different values to the same database column if `token` falls back to `id`. - Updates session data construction to use the new `sessionId` and `tokenValue` logic. --- <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 21:27: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#30343