Updating better-auth schema after re-defining Prisma Schema
Hi Guys.
I have a NextJs15 application that uses Prisma as an ORM and used the " bunx @better-auth/cli generate" to generate my Prisma schema and all worked perfectly. I them proceded by creating all my necesarry methods for login on the server side and all this worked flawlessly as well.
The problem I have is now that I updated my Prisma Schema and ran the "bunx prisma migrate dev --name add_user_role_fields " migration it seems that even if I then try and update the Better-Auth Schema it does not want to work. I run this for the update: "bunx @better-auth/cli@latest generate --output lib/generated/prisma/schema.prisma"
No when I try and access my new attribute in the User table (role) through a session.user it is not available?
How do I update my Better-Auth Schema to access the new tables and table attricutes?
10 Replies
Can you show me both your auth and your auth client files?
Make sure to use the your custom generated Prisma client import with in the auth config file that you had
import { betterAuth } from "better-auth";
import { nextCookies } from "better-auth/next-js";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "@/lib/generated/prisma";
const prisma = new PrismaClient();
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
emailAndPassword: {
enabled: true }, plugins: [ nextCookies(), ], }); and: import { createAuthClient } from "better-auth/react" export const authClient = createAuthClient({ /** the base url of the server (optional if you're using the same domain) */ baseURL: "http://localhost:3000" })
enabled: true }, plugins: [ nextCookies(), ], }); and: import { createAuthClient } from "better-auth/react" export const authClient = createAuthClient({ /** the base url of the server (optional if you're using the same domain) */ baseURL: "http://localhost:3000" })
you should extend your user table like this:
https://www.better-auth.com/docs/concepts/database#extending-core-schema
Database | Better Auth
Learn how to use a database with Better Auth.
So by using secondary storage? Or am I missing you?
Look for extending core schema
an example looks like this:

Thank @Ping ❤️
Once more thing. I foresee a lot of issues when I try and run bun run build because the linter is probably going to try and lint the generated files.
You guys have a suggestion regarding this?
Are you talking about the prisma files?
Nevermind. I got it done but yes, all the files being generated by prisma once you run the migrations get linted as well and that will cause an bunch of issues because it generates JS and not TS. 🤮