diff --git a/src/server/api/routers/common.ts b/src/server/api/routers/common.ts index e5a128e..00f3af7 100644 --- a/src/server/api/routers/common.ts +++ b/src/server/api/routers/common.ts @@ -1,7 +1,6 @@ import { z } from "zod"; - import { createTRPCRouter, publicProcedure } from "@/server/api/trpc"; -import { prisma } from "@/server/db"; +import prisma from "@/server/db"; export interface StatisticData { id: string; diff --git a/src/server/api/routers/frs.ts b/src/server/api/routers/frs.ts index d1ff2ad..62bb1a9 100644 --- a/src/server/api/routers/frs.ts +++ b/src/server/api/routers/frs.ts @@ -1,9 +1,8 @@ +import { titleSchema } from "@/app/my-frs/schema"; +import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc"; import { TRPCError } from "@trpc/server"; import { z } from "zod"; - -import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc"; -import { prisma } from "@/server/db"; -import { titleSchema } from "@/app/my-frs/schema"; +import prisma from "@/server/db"; const frsPlanSchema = z.object({ title: titleSchema, diff --git a/src/server/api/routers/trade-matkul.ts b/src/server/api/routers/trade-matkul.ts index e7cb910..c30fee8 100644 --- a/src/server/api/routers/trade-matkul.ts +++ b/src/server/api/routers/trade-matkul.ts @@ -1,12 +1,11 @@ import { TRPCError } from "@trpc/server"; import { z } from "zod"; - import { createTRPCRouter, protectedProcedure, publicProcedure, } from "@/server/api/trpc"; -import { prisma } from "@/server/db"; +import prisma from "@/server/db"; export const tradeMatkulRouter = createTRPCRouter({ createTradeMatkul: protectedProcedure diff --git a/src/server/api/routers/user.ts b/src/server/api/routers/user.ts index d4cc642..05ef1e2 100644 --- a/src/server/api/routers/user.ts +++ b/src/server/api/routers/user.ts @@ -1,3 +1,15 @@ +import { forgotPasswordSchema } from "@/app/lupa-password/schema"; +import { editProfileSchema } from "@/app/profil/schema"; +import { registerSchema } from "@/app/register/schema"; +import { changePasswordSchema } from "@/app/ubah-password/schema"; +import { env } from "@/env.mjs"; +import { passwordSchema } from "@/lib/schema"; +import { + createTRPCRouter, + protectedProcedure, + publicProcedure, +} from "@/server/api/trpc"; +import prisma from "@/server/db"; import { TRPCError } from "@trpc/server"; import { kv } from "@vercel/kv"; import bcrypt from "bcryptjs"; @@ -5,21 +17,6 @@ import jwt from "jsonwebtoken"; import { Resend } from "resend"; import { z } from "zod"; -import { - createTRPCRouter, - protectedProcedure, - publicProcedure, -} from "@/server/api/trpc"; -import { prisma } from "@/server/db"; - -import { env } from "@/env.mjs"; - -import { passwordSchema } from "@/lib/schema"; -import { registerSchema } from "@/app/register/schema"; -import { editProfileSchema } from "@/app/profil/schema"; -import { changePasswordSchema } from "@/app/ubah-password/schema"; -import { forgotPasswordSchema } from "@/app/lupa-password/schema"; - export const userRouter = createTRPCRouter({ register: publicProcedure .input(registerSchema) diff --git a/src/server/auth.ts b/src/server/auth.ts index 5e1fccb..ab43aae 100644 --- a/src/server/auth.ts +++ b/src/server/auth.ts @@ -4,11 +4,10 @@ import { type NextAuthOptions, } from "next-auth"; import CredentialsProvider from "next-auth/providers/credentials"; - import { env } from "@/env.mjs"; import bcrypt from "bcryptjs"; import jwt from "jsonwebtoken"; -import { prisma } from "./db"; +import prisma from "@/server/db"; export interface LoginResponseData { username: string; diff --git a/src/server/db.ts b/src/server/db.ts index 2e118a2..2b4b6f8 100644 --- a/src/server/db.ts +++ b/src/server/db.ts @@ -1,24 +1,17 @@ import { env } from "@/env.mjs"; import { PrismaClient } from "@prisma/client"; -import { Client } from "@planetscale/database"; -import { fetch as undiciFetch } from "undici"; -import { PrismaPlanetScale } from "@prisma/adapter-planetscale"; const prismaClientSingleton = () => { - const client = new Client({ url: env.DATABASE_URL, fetch: undiciFetch }); - const adapter = new PrismaPlanetScale(client); - return new PrismaClient({ - log: env.NODE_ENV === "development" ? ["error", "warn"] : ["error"], - adapter, - }); + return new PrismaClient(); }; -type PrismaClientSingleton = ReturnType; +declare global { + // eslint-disable-next-line no-var + var prisma: undefined | ReturnType; +} -const globalForPrisma = globalThis as unknown as { - prisma: PrismaClientSingleton | undefined; -}; +const prisma = globalThis.prisma ?? prismaClientSingleton(); -export const prisma = globalForPrisma.prisma ?? prismaClientSingleton(); +export default prisma; -if (env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; +if (env.NODE_ENV !== "production") globalThis.prisma = prisma;