Skip to content

Commit ea3fdaa

Browse files
committed
make single instance of prisma
1 parent 14dc64f commit ea3fdaa

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

‎pages/api/auth/[...nextauth].ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import NextAuth from "next-auth";
22
import GithubProvider from "next-auth/providers/github";
33
import { PrismaAdapter } from "@next-auth/prisma-adapter";
4-
import { PrismaClient } from "@prisma/client";
5-
6-
const prisma = new PrismaClient();
4+
import client from "@/prisma-client";
75

86
export default NextAuth({
9-
adapter: PrismaAdapter(prisma),
7+
adapter: PrismaAdapter(client),
108
providers: [
119
GithubProvider({
1210
clientId: process.env.GITHUB_ID,

‎pages/api/blog/index.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { PrismaClient } from "@prisma/client";
21
import type { NextApiHandler } from "next";
3-
4-
const prisma = new PrismaClient();
2+
import client from "@/prisma-client";
53

64
const handler: NextApiHandler = async (req, res) => {
75
if (req.method === "GET") {
8-
const posts = prisma.post.findMany();
6+
const posts = client.post.findMany();
97
res.status(200).json({ status: "success", data: posts });
108
} else if (req.method === "POST") {
119
} else {

‎prisma-client.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { PrismaClient } from "@prisma/client";
2+
3+
const client = new PrismaClient();
4+
5+
export default client;

0 commit comments

Comments
 (0)