File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed
Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change 1- import 'server-only' ;
2-
31import { PrismaClient } from '@prisma/client' ;
42
5- const globalForPrisma = global as unknown as { prisma : PrismaClient } ;
3+ // Prevent PrismaClient instantiation in browser environment
4+ const globalForPrisma = globalThis as unknown as { prisma : PrismaClient | undefined } ;
65
7- export const prisma =
8- globalForPrisma . prisma ||
9- new PrismaClient ( {
10- log : [ 'query' ] ,
6+ function createPrismaClient ( ) : PrismaClient {
7+ if ( typeof window !== 'undefined' ) {
8+ throw new Error ( 'PrismaClient cannot be used in the browser' ) ;
9+ }
10+ return new PrismaClient ( {
11+ log : process . env . NODE_ENV === 'development' ? [ 'query' ] : [ ] ,
1112 } ) ;
13+ }
14+
15+ export const prisma = globalForPrisma . prisma ?? createPrismaClient ( ) ;
1216
13- if ( process . env . NODE_ENV !== 'production' ) globalForPrisma . prisma = prisma ;
17+ if ( process . env . NODE_ENV !== 'production' ) {
18+ globalForPrisma . prisma = prisma ;
19+ }
You can’t perform that action at this time.
0 commit comments