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
Ping
Ping2w ago
Can you show me both your auth and your auth client files?
KiNFiSH
KiNFiSH2w ago
Make sure to use the your custom generated Prisma client import with in the auth config file that you had
SnyMes
SnyMesOP2w ago
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" })
Ping
Ping2w ago
Database | Better Auth
Learn how to use a database with Better Auth.
SnyMes
SnyMesOP2w ago
So by using secondary storage? Or am I missing you?
Ping
Ping2w ago
Look for extending core schema
Ping
Ping2w ago
an example looks like this:
No description
SnyMes
SnyMesOP2w ago
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?
Ping
Ping2w ago
Are you talking about the prisma files?
SnyMes
SnyMesOP2w ago
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. 🤮

Did you find this page helpful?