Prisma + better-auth: schema type issue

I have been struggling with this issue for the last 3 hours. Keep looking into the why I am getting an error on type after running the generate command and making a push to my local PostgreSQL database. I have setup a simple form using ShadCN (they also use react-hook-form under the hood) and some other components such as the input field. Could anyone please help me out?
No description
14 Replies
Jacob | idohtml
Jacob | idohtmlOP4d ago
OBS ! Here is my schema.prisma file
generator client {
provider = "prisma-client-js"
output = "app/generated/prisma/client"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id @default(uuid())
name String?
email String @unique
emailVerified Boolean? // Change from DateTime? to Boolean?
password String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

image String?
sessions Session[]
accounts Account[]

@@map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime
updatedAt DateTime
ipAddress String?
userAgent String?
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@unique([token])
@@map("session")
}

model Account {
id String @id
accountId String
providerId String
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
accessToken String?
refreshToken String?
idToken String?
accessTokenExpiresAt DateTime?
refreshTokenExpiresAt DateTime?
scope String?
password String?
type String?
createdAt DateTime
updatedAt DateTime

@@map("account")
}

model Verification {
id String @id
identifier String
value String
expiresAt DateTime
createdAt DateTime?
updatedAt DateTime?

@@map("verification")
}
generator client {
provider = "prisma-client-js"
output = "app/generated/prisma/client"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id @default(uuid())
name String?
email String @unique
emailVerified Boolean? // Change from DateTime? to Boolean?
password String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

image String?
sessions Session[]
accounts Account[]

@@map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime
updatedAt DateTime
ipAddress String?
userAgent String?
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@unique([token])
@@map("session")
}

model Account {
id String @id
accountId String
providerId String
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
accessToken String?
refreshToken String?
idToken String?
accessTokenExpiresAt DateTime?
refreshTokenExpiresAt DateTime?
scope String?
password String?
type String?
createdAt DateTime
updatedAt DateTime

@@map("account")
}

model Verification {
id String @id
identifier String
value String
expiresAt DateTime
createdAt DateTime?
updatedAt DateTime?

@@map("verification")
}
Jacob | idohtml
Jacob | idohtmlOP4d ago
Also one more thing I have no clue to why it's happening but because of the generator client where it says output = "app/generated/prisma/client I get this random folder generated to our project. I have never seen this before...
No description
KiNFiSH
KiNFiSH4d ago
if it is from a prisma ig you have to restart the dev server send ur auth config file
Jacob | idohtml
Jacob | idohtmlOP4d ago
I have done that multiple time but I still get the same error when i fill in the sign up form
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { nextCookies } from "better-auth/next-js";
import prisma from "./database/prisma";

export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
secret: process.env.AUTH_SECRET!,
emailAndPassword: {
enabled: true,
autoSignIn: false,
},
plugins: [nextCookies()],
});
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { nextCookies } from "better-auth/next-js";
import prisma from "./database/prisma";

export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
secret: process.env.AUTH_SECRET!,
emailAndPassword: {
enabled: true,
autoSignIn: false,
},
plugins: [nextCookies()],
});
KiNFiSH
KiNFiSH4d ago
what about ./database/prisma can you send that one as well
Jacob | idohtml
Jacob | idohtmlOP4d ago
import { PrismaClient } from "@prisma/client";

const prismaClientSingleton = () => {
return new PrismaClient();
};

declare const globalThis: {
prismaGlobal: ReturnType<typeof prismaClientSingleton>;
} & typeof global;

const prisma = globalThis.prismaGlobal ?? prismaClientSingleton();

export default prisma;

if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = prisma;
import { PrismaClient } from "@prisma/client";

const prismaClientSingleton = () => {
return new PrismaClient();
};

declare const globalThis: {
prismaGlobal: ReturnType<typeof prismaClientSingleton>;
} & typeof global;

const prisma = globalThis.prismaGlobal ?? prismaClientSingleton();

export default prisma;

if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = prisma;
KiNFiSH
KiNFiSH4d ago
replace the import of @prisma/client with the generated client import {PrismaClient} from "app/generated/prisma/client" or if you have an alias make sure to prefix that as well
Jacob | idohtml
Jacob | idohtmlOP4d ago
Like this right?
import { PrismaClient } from "@/prisma/app/generated/prisma/client";

const prismaClientSingleton = () => {
return new PrismaClient();
};

declare const globalThis: {
prismaGlobal: ReturnType<typeof prismaClientSingleton>;
} & typeof global;

const prisma = globalThis.prismaGlobal ?? prismaClientSingleton();

export default prisma;

if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = prisma;
import { PrismaClient } from "@/prisma/app/generated/prisma/client";

const prismaClientSingleton = () => {
return new PrismaClient();
};

declare const globalThis: {
prismaGlobal: ReturnType<typeof prismaClientSingleton>;
} & typeof global;

const prisma = globalThis.prismaGlobal ?? prismaClientSingleton();

export default prisma;

if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = prisma;
KiNFiSH
KiNFiSH4d ago
so do you get an autocompilation for PrismaClient ryt ?
Jacob | idohtml
Jacob | idohtmlOP4d ago
ryt?
KiNFiSH
KiNFiSH4d ago
yeah. i was making sure if PrismaClient is defined when you import from the path try it and lemme know if that does not work
Jacob | idohtml
Jacob | idohtmlOP4d ago
Yeah seems to work now but I still don't understand why I need that output thing? I used to do it like this before
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
KiNFiSH
KiNFiSH4d ago
it is from prisma not from better-auth . they have released it and change a lot of their query engine. make sure to stick with docs here and on prisma as well this is also fine the problem is when you want a custom output and it is need a custom client that has a query engine filled with the your schema config
Jacob | idohtml
Jacob | idohtmlOP4d ago
That's so good to know Well however. Thank you so, so much for the help provided. I appreciated it highly mate 🙏

Did you find this page helpful?