-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.config.ts
57 lines (52 loc) · 1.84 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
51
52
53
54
55
56
import type { NextAuthConfig } from "next-auth";
import Github from "next-auth/providers/github"
import Google from "next-auth/providers/google"
import Twitter from "next-auth/providers/twitter"
import { signInSchema } from "./lib/formSchema"
import { compare } from "bcryptjs"
import Credentials from "next-auth/providers/credentials"
import { db } from "./lib/prisma"
export const authConfig = {
providers: [
Github({
clientId: process.env.AUTH_GITHUB_CLIENT_ID,
clientSecret: process.env.AUTH_GITHUB_CLIENT_SECRET,
authorization: {
params: {
prompt: "consent",
access_type: "offline",
response_type: "code",
},
},
}),
Google({
clientId: process.env.AUTH_GOOGLE_CLIENT_ID,
clientSecret: process.env.AUTH_GOOGLE_CLIENT_SECRET,
}),
Twitter({
clientId: process.env.AUTH_TWITTER_ID,
clientSecret: process.env.AUTH_TWITTER_SECRET,
}),
Credentials({
async authorize(credentials) {
const validatedFields = signInSchema.safeParse(credentials);
if (!validatedFields.success) {
return null;
}
// Validate that the user exists
const { email, password } = validatedFields.data;
const user = await db.user.findUnique({
where: { email },
});
if (!user) {
return null;
}
const isPasswordMatch = await compare(password, user.password);
if (!isPasswordMatch) {
return null;
}
return user;
},
}),
],
} satisfies NextAuthConfig