[PR #2656] [MERGED] fix(mongo-adapter): fix incorrect transformation of findOneAndX outputs #12674

Closed
opened 2026-04-13 08:31:53 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/2656
Author: @matt-shipman
Created: 5/14/2025
Status: Merged
Merged: 6/7/2025
Merged by: @Bekacru

Base: mainHead: fix/mongodb-adapter


📝 Commits (4)

  • c46c023 fix(mongo-adapter): fix incorrect transformation of findOneAndX outputs
  • 7256760 fix(mongo-adapter): fix incorrect transformation of findOneAndX outputs
  • 0f046f5 fix(mongo-adapter): fix incorrect transformation of findOneAndX outputs
  • 0243236 lint

📊 Changes

1 file changed (+6 additions, -4 deletions)

View changed files

📝 packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts (+6 -4)

📄 Description

The MongoDB adapter was using the res from the findOneAndX operations instead of using res.value. This was causing all properties to have undefined as their value. This causes a APIError: Failed to get session to be thrown when a session is being refreshed once past updateAge.

The return value from findOneAndX is Promise<WithId<TSchema> | ModifyResult<TSchema> | null>.

MongoDB type definitions:
https://github.com/mongodb/node-mongodb-native/blob/main/src/collection.ts#L100
https://github.com/mongodb/node-mongodb-native/blob/main/src/collection.ts#L982


🔄 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/2656 **Author:** [@matt-shipman](https://github.com/matt-shipman) **Created:** 5/14/2025 **Status:** ✅ Merged **Merged:** 6/7/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `fix/mongodb-adapter` --- ### 📝 Commits (4) - [`c46c023`](https://github.com/better-auth/better-auth/commit/c46c02383ade97e5eb67b1a510f918f06c8ee531) fix(mongo-adapter): fix incorrect transformation of findOneAndX outputs - [`7256760`](https://github.com/better-auth/better-auth/commit/7256760110a179cae668455f2061552961b8492a) fix(mongo-adapter): fix incorrect transformation of findOneAndX outputs - [`0f046f5`](https://github.com/better-auth/better-auth/commit/0f046f56d8414046bbc38bf2e8688199c5c5d567) fix(mongo-adapter): fix incorrect transformation of findOneAndX outputs - [`0243236`](https://github.com/better-auth/better-auth/commit/024323618b760073809dac16d7736bde517dfb4a) lint ### 📊 Changes **1 file changed** (+6 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts` (+6 -4) </details> ### 📄 Description The MongoDB adapter was using the `res` from the `findOneAndX` operations instead of using `res.value`. This was causing all properties to have `undefined` as their value. This causes a `APIError: Failed to get session` to be thrown when a session is being refreshed once past `updateAge`. The return value from `findOneAndX` is `Promise<WithId<TSchema> | ModifyResult<TSchema> | null>`. MongoDB type definitions: https://github.com/mongodb/node-mongodb-native/blob/main/src/collection.ts#L100 https://github.com/mongodb/node-mongodb-native/blob/main/src/collection.ts#L982 --- <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-13 08:31:53 -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#12674