[PR #9068] fix(core): honor forceAllowId UUIDs on postgres adapters #16661

Open
opened 2026-04-13 10:38:04 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/9068
Author: @GautamBytes
Created: 4/9/2026
Status: 🔄 Open

Base: mainHead: fix/force-allow-id-uuid


📝 Commits (3)

  • dace5a2 fix: honor forced UUID ids on postgres adapters
  • 31748a3 test: use unique email in postgres uuid hook regression
  • 84a055d chore: fix CI for forced UUID regression

📊 Changes

4 files changed (+93 additions, -2 deletions)

View changed files

.changeset/force-allow-id-uuid.md (+5 -0)
📝 e2e/adapter/test/adapter-factory/adapter-factory.test.ts (+35 -0)
📝 packages/better-auth/src/db/db.test.ts (+51 -0)
📝 packages/core/src/db/adapter/get-id-field.ts (+2 -2)

📄 Description

Closes #9056

Summary

This fixes a bug where a user ID returned from databaseHooks.user.create.before was dropped when advanced.database.generateId = "uuid" was used with PostgreSQL-backed adapters.

Root Cause

In packages/core/src/db/adapter/get-id-field.ts, the UUID input transform returned undefined for adapters with supportsUUIDs: true before checking forceAllowId. That meant PostgreSQL fell back to its default UUID generator even when a valid UUID had been explicitly provided.

Changes

  • move the forceAllowId UUID validation/return ahead of the supportsUUIDs early return in the core ID transform
  • add an adapter-factory regression covering forceAllowId: true with supportsUUIDs: true
  • add a Better Auth DB regression covering the reported databaseHooks.user.create.before sign-up flow on PostgreSQL

Summary by cubic

Fixes a bug where a forced UUID was ignored on PostgreSQL-backed adapters when advanced.database.generateId = "uuid". Now, when forceAllowId is true, a provided UUID (e.g., from databaseHooks.user.create.before) is preserved.

  • Bug Fixes
    • Checked forceAllowId before the supportsUUIDs early return in the core ID transform.
    • Added regression tests for adapters with supportsUUIDs: true and the Postgres sign-up flow via databaseHooks.user.create.before in better-auth.
    • Used a unique email in the Postgres regression test to avoid collisions in CI.

Written for commit 84a055db79. Summary will update 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/9068 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 4/9/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/force-allow-id-uuid` --- ### 📝 Commits (3) - [`dace5a2`](https://github.com/better-auth/better-auth/commit/dace5a2ed6839652be5590ceeea82e7f641c5aed) fix: honor forced UUID ids on postgres adapters - [`31748a3`](https://github.com/better-auth/better-auth/commit/31748a3ed5374bf58236738d535cfec7ca2d2279) test: use unique email in postgres uuid hook regression - [`84a055d`](https://github.com/better-auth/better-auth/commit/84a055db79462c593aa28b4b920c33bf065b8b42) chore: fix CI for forced UUID regression ### 📊 Changes **4 files changed** (+93 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/force-allow-id-uuid.md` (+5 -0) 📝 `e2e/adapter/test/adapter-factory/adapter-factory.test.ts` (+35 -0) 📝 `packages/better-auth/src/db/db.test.ts` (+51 -0) 📝 `packages/core/src/db/adapter/get-id-field.ts` (+2 -2) </details> ### 📄 Description Closes #9056 ## Summary This fixes a bug where a user ID returned from `databaseHooks.user.create.before` was dropped when `advanced.database.generateId = "uuid"` was used with PostgreSQL-backed adapters. ## Root Cause In `packages/core/src/db/adapter/get-id-field.ts`, the UUID input transform returned `undefined` for adapters with `supportsUUIDs: true` before checking `forceAllowId`. That meant PostgreSQL fell back to its default UUID generator even when a valid UUID had been explicitly provided. ## Changes - move the `forceAllowId` UUID validation/return ahead of the `supportsUUIDs` early return in the core ID transform - add an adapter-factory regression covering `forceAllowId: true` with `supportsUUIDs: true` - add a Better Auth DB regression covering the reported `databaseHooks.user.create.before` sign-up flow on PostgreSQL <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes a bug where a forced UUID was ignored on PostgreSQL-backed adapters when `advanced.database.generateId = "uuid"`. Now, when `forceAllowId` is true, a provided UUID (e.g., from `databaseHooks.user.create.before`) is preserved. - **Bug Fixes** - Checked `forceAllowId` before the `supportsUUIDs` early return in the core ID transform. - Added regression tests for adapters with `supportsUUIDs: true` and the Postgres sign-up flow via `databaseHooks.user.create.before` in `better-auth`. - Used a unique email in the Postgres regression test to avoid collisions in CI. <sup>Written for commit 84a055db79462c593aa28b4b920c33bf065b8b42. Summary will update 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-04-13 10:38:04 -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#16661