import NextAuth from "next-auth"; import Credentials from "next-auth/providers/credentials"; import bcrypt from "bcryptjs"; import { prisma } from "./prisma"; export const { handlers, signIn, signOut, auth } = NextAuth({ providers: [ Credentials({ credentials: { email: { label: "Email", type: "email" }, password: { label: "Password", type: "password" }, }, async authorize(credentials) { const user = await prisma.user.findUnique({ where: { email: credentials.email as string }, }); if (!user) return null; const valid = await bcrypt.compare( credentials.password as string, user.password ); return valid ? { id: user.id, email: user.email, name: user.name } : null; }, }), ], session: { strategy: "jwt" }, pages: { signIn: "/login", }, secret: process.env.NEXTAUTH_SECRET, });