-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
39 lines (32 loc) · 1017 Bytes
/
auth.ts
File metadata and controls
39 lines (32 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import prisma from "@/lib/prisma";
import bcrypt from "bcryptjs";
import NextAuth from "next-auth";
import Credentials from "next-auth/providers/credentials";
import { authConfig } from "./auth.config";
export const { handlers, signIn, signOut, auth } = NextAuth({
...authConfig,
providers: [
Credentials({
credentials: {
email: { label: "Email", type: "email" },
password: { label: "Password", type: "password" },
},
async authorize(credentials) {
const email = credentials?.email as string;
const password = credentials?.password as string;
if (!email || !password) return null;
const user = await prisma.user.findUnique({
where: { email },
});
if (!user) return null;
const isValid = await bcrypt.compare(password, user.password);
if (!isValid) return null;
return {
id: user.id,
name: user.name,
email: user.email,
};
},
}),
],
});