Recommended way to setup in a monorepo
Your proposed approach is a good way to handle the dependency injection in a pnpm monorepo. Injecting the Prisma client into your shared auth package via a function argument allows you to keep your Better Auth configuration decoupled from your specific Prisma setup. This way, the consuming package (e.g., your API) can supply its own PrismaClient instance, ensuring that your adapter and schema generation processes work with the correct instance and any custom Prisma client output paths you might have configured [1].
Just make sure that when importing your PrismaClient in your API, you reference the correct module (especially if you've set up a custom output directory in your Prisma configuration) [1]. This approach is in line with practices for monorepo setups, as also highlighted in discussions around Prisma adapter behavior in monorepos [4].
In summary, your code snippet is a valid strategy:
This pattern keeps your authentication logic modular and allows you to share the auth configuration across multiple projects within your workspace.
Sources:
[1] Prisma | Better Auth
[4] Prisma monorepo schema generation in existing project
Just make sure that when importing your PrismaClient in your API, you reference the correct module (especially if you've set up a custom output directory in your Prisma configuration) [1]. This approach is in line with practices for monorepo setups, as also highlighted in discussions around Prisma adapter behavior in monorepos [4].
In summary, your code snippet is a valid strategy:
This pattern keeps your authentication logic modular and allows you to share the auth configuration across multiple projects within your workspace.
Sources:
[1] Prisma | Better Auth
[4] Prisma monorepo schema generation in existing project
GitHub
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
Is this suited for github? Yes, this is suited for github To Reproduce Create pnpm monorepositor Have prisma in a separate package with prisma client being exported Import client to auth.ts and use...