-
Notifications
You must be signed in to change notification settings - Fork 3
/
auth.config.ts
50 lines (43 loc) · 1.44 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
47
48
49
50
import prisma from "@/lib/prismaClient";
import bcrypt from "bcryptjs";
import { NextAuthConfig } from "next-auth";
import Credentials from "next-auth/providers/credentials";
import GitHub from "next-auth/providers/github";
import Google from "next-auth/providers/google";
import { loginSchema } from "./schema";
export default {
providers: [
GitHub({
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
}),
Google({
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
}),
Credentials({
credentials: {
email: {},
password: {},
},
authorize: async (credentials) => {
const validateFields = loginSchema.safeParse(credentials);
if (validateFields.success) {
const { email, password } = validateFields.data;
const user = await prisma.user.findFirst({
where: {
email,
},
});
if (!user || !user.password) return null;
const isPasswordValid = await bcrypt.compare(
password,
user.password
);
if (isPasswordValid) return user;
}
return null;
},
}),
],
} satisfies NextAuthConfig;