[GH-ISSUE #5387] MongoDB adapter customIdGenerator overrides user's generateId config in v1.3.24-v1.3.27 #27552

Closed
opened 2026-04-17 18:37:42 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @eranmiller on GitHub (Oct 17, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5387

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Set up better-auth v1.3.27 with MongoDB adapter
  2. Configure custom ID generation with ULID:
    betterAuth({
      database: mongodbAdapter(mongoDb),
      advanced: {
        database: {
          generateId: () => ulid(),
        },
      },
    })
    
  3. Create a new user via OAuth (e.g., Google)
  4. Check the user's ID in MongoDB

Current vs. Expected behavior

Result: ID is a 24-character ObjectId, not a 26-character ULID

  • v1.3.23: User's generateId works correctly, ULIDs generated
  • v1.3.24-v1.3.27: MongoDB adapter's customIdGenerator takes precedence, ObjectIds generated
  • Rollback to v1.3.23: ULIDs work again

What version of Better Auth are you using?

1.3.27

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025",
    "release": "6.6.87.2-microsoft-standard-WSL2",
    "cpuCount": 8,
    "cpuModel": "11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz",
    "totalMemory": "7.61 GB",
    "freeMemory": "3.33 GB"
  },
  "node": {
    "version": "v22.13.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.2"
  },
  "frameworks": [
    {
      "name": "svelte",
      "version": "5.40.2"
    },
    {
      "name": "@sveltejs/kit",
      "version": "^2.47.0"
    }
  ],
  "databases": [
    {
      "name": "mongodb",
      "version": "^6.20.0"
    }
  ],
  "betterAuth": {
    "version": "1.3.27",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

betterAuth({
     database: mongodbAdapter(mongoDb),
     advanced: {
       database: {
         generateId: () => ulid(),
       },
     },
   })

Additional context

This regression was discovered through production testing with actual user creation via Google OAuth. The issue is NOT documented in:

  • Release notes for v1.3.24, v1.3.25, v1.3.26, or v1.3.27
  • GitHub issues (no existing reports found)
  • Migration guides

This may be related to PR #5058 which deprecated root-level generateId and moved it to advanced.database.generateId only. The configuration API change may have introduced a precedence bug in the adapter factory for MongoDB specifically.

Originally created by @eranmiller on GitHub (Oct 17, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5387 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Set up better-auth v1.3.27 with MongoDB adapter 2. Configure custom ID generation with ULID: ```typescript betterAuth({ database: mongodbAdapter(mongoDb), advanced: { database: { generateId: () => ulid(), }, }, }) ``` 3. Create a new user via OAuth (e.g., Google) 4. Check the user's ID in MongoDB ### Current vs. Expected behavior **Result:** ID is a 24-character ObjectId, not a 26-character ULID - ✅ **v1.3.23:** User's `generateId` works correctly, ULIDs generated - ❌ **v1.3.24-v1.3.27:** MongoDB adapter's `customIdGenerator` takes precedence, ObjectIds generated - ✅ **Rollback to v1.3.23:** ULIDs work again ### What version of Better Auth are you using? 1.3.27 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025", "release": "6.6.87.2-microsoft-standard-WSL2", "cpuCount": 8, "cpuModel": "11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz", "totalMemory": "7.61 GB", "freeMemory": "3.33 GB" }, "node": { "version": "v22.13.1", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.2" }, "frameworks": [ { "name": "svelte", "version": "5.40.2" }, { "name": "@sveltejs/kit", "version": "^2.47.0" } ], "databases": [ { "name": "mongodb", "version": "^6.20.0" } ], "betterAuth": { "version": "1.3.27", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript betterAuth({ database: mongodbAdapter(mongoDb), advanced: { database: { generateId: () => ulid(), }, }, }) ``` ### Additional context This regression was discovered through production testing with actual user creation via Google OAuth. The issue is **NOT documented** in: - Release notes for v1.3.24, v1.3.25, v1.3.26, or v1.3.27 - GitHub issues (no existing reports found) - Migration guides This may be related to PR #5058 which deprecated root-level `generateId` and moved it to `advanced.database.generateId` only. The configuration API change may have introduced a precedence bug in the adapter factory for MongoDB specifically.
GiteaMirror added the locked label 2026-04-17 18:37:42 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 17, 2025):

Hi @eranmiller! I'm Dosu and I’m helping the better-auth team.

You’ve correctly identified a regression: in Better Auth v1.3.24–v1.3.27, the MongoDB adapter’s internal customIdGenerator takes precedence over your advanced.database.generateId config, so custom ID generators like ULID are ignored and ObjectIds are always used. This change was introduced around PR #5058, which refactored how ID generation is handled and deprecated the root-level generateId option, but the MongoDB adapter’s logic now overrides user config in these versions, breaking expected behavior for custom IDs. This issue is not documented in release notes or migration guides and appears to be an unintentional regression rather than a documented breaking change. Rolling back to v1.3.23 is currently the only reliable workaround if you need custom ID generation with MongoDB.

Reference: PR #5058 details

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3416127110 --> @dosubot[bot] commented on GitHub (Oct 17, 2025): <!-- Greeting --> Hi @eranmiller! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> You’ve correctly identified a regression: in Better Auth v1.3.24–v1.3.27, the MongoDB adapter’s internal `customIdGenerator` takes precedence over your `advanced.database.generateId` config, so custom ID generators like ULID are ignored and ObjectIds are always used. This change was introduced around PR #5058, which refactored how ID generation is handled and deprecated the root-level `generateId` option, but the MongoDB adapter’s logic now overrides user config in these versions, breaking expected behavior for custom IDs. This issue is not documented in release notes or migration guides and appears to be an unintentional regression rather than a documented breaking change. Rolling back to v1.3.23 is currently the only reliable workaround if you need custom ID generation with MongoDB. Reference: [PR #5058 details](https://github.com/better-auth/better-auth/pull/5058) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/7f3d86a1-f32a-43e3-bcf2-5ba3648541e3?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7f3d86a1-f32a-43e3-bcf2-5ba3648541e3?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7f3d86a1-f32a-43e3-bcf2-5ba3648541e3?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7f3d86a1-f32a-43e3-bcf2-5ba3648541e3?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7f3d86a1-f32a-43e3-bcf2-5ba3648541e3?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7f3d86a1-f32a-43e3-bcf2-5ba3648541e3?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7f3d86a1-f32a-43e3-bcf2-5ba3648541e3?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/5387)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27552