-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.config.ts
More file actions
31 lines (23 loc) · 813 Bytes
/
auth.config.ts
File metadata and controls
31 lines (23 loc) · 813 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
import type { NextAuthConfig } from "next-auth";
import credentials from "next-auth/providers/credentials";
import bcrypt from "bcryptjs";
import { signInSchema } from "@/schema/auth-schema";
import { getUserByName } from "./data/user";
export default {
trustHost: true,
providers: [
credentials({
async authorize(credentials) {
const validateFields = signInSchema.safeParse(credentials);
if (validateFields.success) {
const { user_name, password } = validateFields.data;
const user = await getUserByName(user_name);
if (!user) return null;
const passwordMatche = await bcrypt.compare(password, user.password);
if (passwordMatche) return user;
}
return null;
},
}),
],
} satisfies NextAuthConfig;