From a500d6f76b8756fb21657af36e559252d7aa6767 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Fri, 14 Oct 2022 22:43:26 +0200 Subject: [PATCH] use global client everywhere --- db/client.ts | 16 ++++++++++++++++ db/index.ts | 14 +------------- pages/api/auth/[...nextauth].ts | 3 +-- 3 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 db/client.ts diff --git a/db/client.ts b/db/client.ts new file mode 100644 index 0000000..f6890f1 --- /dev/null +++ b/db/client.ts @@ -0,0 +1,16 @@ +import { PrismaClient } from '@prisma/client' + + +declare global { + // allow global `var` declarations + // eslint-disable-next-line no-var + var prisma: PrismaClient | undefined +} + +export const prisma = + global.prisma || + new PrismaClient({ + log: ['query'], + }) + +if (process.env.NODE_ENV !== 'production') global.prisma = prisma diff --git a/db/index.ts b/db/index.ts index fd13b0b..f7bc6ec 100644 --- a/db/index.ts +++ b/db/index.ts @@ -4,19 +4,7 @@ import { getBookedDays as calendarGetBookedDays } from '../lib/googlecalendar' import { uniqueFilter } from '../helpers/array' import { dateFormatBackend, getDays, nowInTz } from '../helpers/date' -declare global { - // allow global `var` declarations - // eslint-disable-next-line no-var - var prisma: PrismaClient | undefined -} - -export const prisma = - global.prisma || - new PrismaClient({ - log: ['query'], - }) - -if (process.env.NODE_ENV !== 'production') global.prisma = prisma +import { prisma } from './client' export async function getBookedDays( uuidsToIngore?: string[] diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index b4f3c21..89090b2 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -3,9 +3,8 @@ import EmailProvider from 'next-auth/providers/email' import GitHubProvider from 'next-auth/providers/github' import { PrismaAdapter } from "@next-auth/prisma-adapter" -import { PrismaClient } from "@prisma/client" -const prisma = new PrismaClient() +import { prisma } from '../../../db/client'; const ADMIN_EMAIL = process.env.ADMIN_EMAIL const GITHUB_USERS_GRANTED = ['111471']