-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.config.ts
46 lines (37 loc) · 1.1 KB
/
auth.config.ts
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
40
41
42
43
44
45
46
import type { NextAuthConfig } from "next-auth";
import { compare } from "bcryptjs";
import Credentials from "next-auth/providers/credentials";
import { LoginSchema } from "./app/_schemas/authSchemas";
import prisma from "./app/_lib/db";
export default {
providers: [
Credentials({
async authorize(credentials) {
if (!credentials?.email || !credentials.password) return null;
const result = LoginSchema.safeParse(credentials);
if (!result.success) return null;
const { email, password } = result.data;
const user = await prisma.user.findUnique({
where: {
email,
},
});
if (!user || !user.password || user.role !== "ADMIN") return null;
const isPasswordValid = await compare(
password as string,
user.password as string,
);
if (!isPasswordValid) return null;
return {
id: user.id.toString(),
email: user.email,
name: user.name,
};
},
}),
],
pages: {
signIn: "/",
error: "/",
},
} satisfies NextAuthConfig;