[GH-ISSUE #1192] list-accounts phoneNumber userId mongodb Invalid id value #8638

Closed
opened 2026-04-13 03:47:05 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @reslear on GitHub (Jan 11, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1192

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

mongodb and phoneNumber plugin,
run listAccounts

Current vs. Expected behavior

I don't know exactly why it's happening, but I can guess:

if userId is ObjectId in mongodb:

CleanShot 2025-01-11 at 23 45 12@2x

CleanShot 2025-01-11 at 23 50 45@2x

findAccounts use userId :

00b3d5a80e/packages/better-auth/src/db/internal-adapter.ts (L701-L712)

but userId not ObjectId only id/_id:

00b3d5a80e/packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts (L10-L12)

What version of Better Auth are you using?

1.1.9

Provide environment information

- nodejs

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  database: mongodbAdapter(db),
  emailAndPassword: {  
    enabled: true
  },
  advanced: {
    generateId: false,
  },
  plugins: [
    phoneNumber()
  ]
});

Additional context

No response

Originally created by @reslear on GitHub (Jan 11, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1192 ### Is this suited for github? - [X] Yes, this is suited for github ### To Reproduce mongodb and phoneNumber plugin, run `listAccounts` ### Current vs. Expected behavior I don't know exactly why it's happening, but I can guess: if userId is ObjectId in mongodb: ![CleanShot 2025-01-11 at 23 45 12@2x](https://github.com/user-attachments/assets/4041490f-e2aa-499b-80bc-5e8067638a24) ![CleanShot 2025-01-11 at 23 50 45@2x](https://github.com/user-attachments/assets/bbec98cc-0677-47e4-ba18-82ffbeb5219e) `findAccounts` use `userId `: https://github.com/better-auth/better-auth/blob/00b3d5a80ef588b35ca910f570fb2de0cc9ad45d/packages/better-auth/src/db/internal-adapter.ts#L701-L712 but `userId` not ObjectId only `id/_id`: https://github.com/better-auth/better-auth/blob/00b3d5a80ef588b35ca910f570fb2de0cc9ad45d/packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts#L10-L12 ### What version of Better Auth are you using? 1.1.9 ### Provide environment information ```bash - nodejs ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ database: mongodbAdapter(db), emailAndPassword: { enabled: true }, advanced: { generateId: false, }, plugins: [ phoneNumber() ] }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 03:47:05 -05:00
Author
Owner

@reslear commented on GitHub (Jan 21, 2025):

@Bekacru i see result user is clean, no userId


listUserAccounts {
  session: {
    ipAddress: '',
    userAgent: 'Mozilla/5.0 ',
    expiresAt: 2025-01-28T17:59:13.014Z,
    token: '7AioLt1g5RKTcGcStDS50NhsPNZyCKL6',
    createdAt: 2025-01-21T17:59:13.014Z,
    updatedAt: 2025-01-21T17:59:13.014Z
  },
  user: { createdAt: Invalid Date, updatedAt: Invalid Date }
}

Image

in phoneNumber plugin i add log:

Image

in console

Image

problem in

9719fee6bf/packages/better-auth/src/db/internal-adapter.ts (L616)

then

9719fee6bf/packages/better-auth/src/db/with-hooks.ts (L59)

<!-- gh-comment-id:2605404034 --> @reslear commented on GitHub (Jan 21, 2025): @Bekacru i see result `user` is clean, no userId ```ts listUserAccounts { session: { ipAddress: '', userAgent: 'Mozilla/5.0 ', expiresAt: 2025-01-28T17:59:13.014Z, token: '7AioLt1g5RKTcGcStDS50NhsPNZyCKL6', createdAt: 2025-01-21T17:59:13.014Z, updatedAt: 2025-01-21T17:59:13.014Z }, user: { createdAt: Invalid Date, updatedAt: Invalid Date } } ``` ![Image](https://github.com/user-attachments/assets/d6f75f2d-e0d3-432d-898f-634b1c0938f6) in phoneNumber plugin i add log: ![Image](https://github.com/user-attachments/assets/148a4ff9-40a8-4234-b67f-81906e9c7272) in console ![Image](https://github.com/user-attachments/assets/66f1224b-f349-4aa2-b6ed-67532c42c646) problem in https://github.com/better-auth/better-auth/blob/9719fee6bfee24b6562ec5e991b8fbe292ff132f/packages/better-auth/src/db/internal-adapter.ts#L616 then https://github.com/better-auth/better-auth/blob/9719fee6bfee24b6562ec5e991b8fbe292ff132f/packages/better-auth/src/db/with-hooks.ts#L59
Author
Owner

@reslear commented on GitHub (Feb 24, 2025):

same in v1.1.21, hi @Bekacru any chance check this problem?

<!-- gh-comment-id:2679665979 --> @reslear commented on GitHub (Feb 24, 2025): same in v1.1.21, hi @Bekacru any chance check this problem?
Author
Owner

@dosubot[bot] commented on GitHub (Jun 13, 2025):

Hi, @reslear. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • You reported an issue with the listAccounts function in the Better Auth library.
  • The problem occurs when using MongoDB and a phoneNumber plugin, with an "Invalid id value" error.
  • You provided code snippets and configuration details for context.
  • Despite updating to version 1.1.21, the issue persists.
  • You requested further assistance from @Bekacru, highlighting specific lines in the code.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If there is no further activity, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:2970840531 --> @dosubot[bot] commented on GitHub (Jun 13, 2025): Hi, @reslear. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - You reported an issue with the `listAccounts` function in the Better Auth library. - The problem occurs when using MongoDB and a phoneNumber plugin, with an "Invalid id value" error. - You provided code snippets and configuration details for context. - Despite updating to version 1.1.21, the issue persists. - You requested further assistance from @Bekacru, highlighting specific lines in the code. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If there is no further activity, this issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@reslear commented on GitHub (Jun 13, 2025):

not stale

<!-- gh-comment-id:2970877609 --> @reslear commented on GitHub (Jun 13, 2025): not stale
Author
Owner

@ping-maxwell commented on GitHub (Aug 9, 2025):

Hey @reslear can you confirm this is still an issue on latest?

<!-- gh-comment-id:3171778602 --> @ping-maxwell commented on GitHub (Aug 9, 2025): Hey @reslear can you confirm this is still an issue on latest?
Author
Owner

@ping-maxwell commented on GitHub (Sep 30, 2025):

Our latest unit tests in https://github.com/better-auth/better-auth/pull/4844 should show that mongodb passes on this.
I'm going to close this, but if it's still an issue feel free to reopen.

<!-- gh-comment-id:3350174924 --> @ping-maxwell commented on GitHub (Sep 30, 2025): Our latest unit tests in https://github.com/better-auth/better-auth/pull/4844 should show that mongodb passes on this. I'm going to close this, but if it's still an issue feel free to reopen.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8638