Issue with MongoDB ObjectID.
I get the following error message when creating a user:
User schema:
Auth instance:
ERROR Failed to create user Better Auth
Invalid prisma.user.create() invocation:
Inconsistent column data: Malformed ObjectID: provided hex string representation must be exactly 12 bytes, instead got: "pFAREXp_F5MYQrfN_ikFq", length 21 for the field 'id'.
Invalid prisma.user.create() invocation: ERROR Failed to create user Better Auth
Invalid prisma.user.create() invocation:
Inconsistent column data: Malformed ObjectID: provided hex string representation must be exactly 12 bytes, instead got: "pFAREXp_F5MYQrfN_ikFq", length 21 for the field 'id'.
Invalid prisma.user.create() invocation:User schema:
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
name String
}model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
name String
}Auth instance:
import { prisma } from "@/db";
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { username } from "better-auth/plugins";
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
},
database: prismaAdapter(prisma, {
provider: "mongodb",
}),
plugins: [username()],
});import { prisma } from "@/db";
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { username } from "better-auth/plugins";
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
},
database: prismaAdapter(prisma, {
provider: "mongodb",
}),
plugins: [username()],
});