fix(auth): generate UUID ids to match uuid schema columns

Better Auth's default id generator emits a nanoid-style string, but
every id column in the schema is typed uuid. Better Auth passes its
generated id explicitly on insert (bypassing the column defaultRandom),
so Postgres rejected every signUp/session/verification insert with
'invalid input syntax for type uuid'. This broke live registration and
the admin seed alike. Configure advanced.database.generateId to return
crypto.randomUUID() so ids match the schema.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Leon TonhäuserandClaude committed 2026-08-10 23:41:47 +02:00
1 parent 2c495ab32a
commit 33b9076cd3
1 file changed
+5
+5
View File
@@ -29,6 +29,11 @@ export function createPortalAuth({
baseURL: env.BETTER_AUTH_URL,
secret: env.BETTER_AUTH_SECRET,
database,
// All id columns are typed `uuid`; Better Auth's default id generator emits
// a nanoid-style string that Postgres rejects with "invalid input syntax
// for type uuid". Generate real UUIDs so inserts (signUp, sessions,
// verifications) match the schema.
advanced: { database: { generateId: () => crypto.randomUUID() } },
emailAndPassword: {
enabled: true,
requireEmailVerification: true,