From 027fee1afa39b0306e9867478936541bf05007e2 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Mon, 16 Feb 2026 22:48:17 -0600 Subject: [PATCH] fix: use UUID for Better Auth ID generation to match Prisma schema Better Auth generates nanoid-style IDs by default, but our Prisma schema uses @db.Uuid columns for all auth tables. This caused P2023 errors when Better Auth tried to insert non-UUID IDs into the verification table during OAuth sign-in. Co-Authored-By: Claude Opus 4.6 --- apps/api/src/auth/auth.config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/api/src/auth/auth.config.ts b/apps/api/src/auth/auth.config.ts index afaf19e..d668eb8 100644 --- a/apps/api/src/auth/auth.config.ts +++ b/apps/api/src/auth/auth.config.ts @@ -1,3 +1,4 @@ +import { randomUUID } from "node:crypto"; import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { genericOAuth } from "better-auth/plugins"; @@ -216,6 +217,7 @@ export function createAuth(prisma: PrismaClient) { updateAge: 60 * 60 * 2, // 2 hours — minimum session age before BetterAuth refreshes the expiry on next request }, advanced: { + generateId: () => randomUUID(), defaultCookieAttributes: { httpOnly: true, secure: process.env.NODE_ENV === "production",