feat(auth): integrate Prisma adapter for Auth.js authentication

This commit is contained in:
ngc2207 2024-12-29 13:59:25 +08:00
parent ee3c6eea47
commit 61f0818f0d
3 changed files with 17 additions and 4 deletions

View File

@ -9,6 +9,8 @@
"lint": "next lint"
},
"dependencies": {
"@auth/prisma-adapter": "^2.7.4",
"@prisma/client": "^6.1.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^0.469.0",
@ -20,13 +22,14 @@
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"eslint": "^8",
"eslint-config-next": "15.0.3"
"eslint-config-next": "15.0.3",
"postcss": "^8",
"prisma": "^6.1.0",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}

View File

@ -1,5 +1,8 @@
import NextAuth from "next-auth";
import { prisma } from "@/lib/prisma";
import { PrismaAdapter } from "@auth/prisma-adapter";
export const { handlers, signIn, signOut, auth } = NextAuth({
adapter: PrismaAdapter(prisma),
providers: [],
});

7
src/lib/prisma.ts Normal file
View File

@ -0,0 +1,7 @@
import { PrismaClient } from "@prisma/client";
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
export const prisma = globalForPrisma.prisma || new PrismaClient();
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;