The error you're encountering is due to trying to run PrismaClient in the browser. PrismaClient is designed to run in a Node.js environment and not in the browser.
In the Vercel Guide (https://vercel.com/guides/nextjs-prisma-postgres), it's recommended to create a single PrismaClient instance that you can import into any file where it's needed. The instance should be created in a prisma.ts file inside the lib/ directory.
Here's how you should structure your PrismaClient instance:
import { PrismaClient } from '@prisma/client';
let prisma: PrismaClient;
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient();
} else {
if (!global.prisma) {
global.prisma = new PrismaClient();
}
prisma = global.prisma;
}
export default prisma;
This code checks if the environment is production or not. If it's production, it creates a new PrismaClient instance. If it's not production (i.e., development), it checks if a PrismaClient instance already exists in the global object. If it does, it uses that. If it doesn't, it creates a new one. This prevents multiple instances of PrismaClient from being created during development, which can lead to too many connections being created with your database.
You can then import this prisma instance into your auth.ts file or any other file where you need to interact with your database.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: