-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
29 lines (24 loc) · 809 Bytes
/
auth.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
import NextAuth from "next-auth"
import Credentials from "next-auth/providers/credentials"
// import { saltAndHashPassword } from "@/utils/password"
import { getUserByEmail } from "./actions/auth-actions"
import { signInSchema } from "./lib/schema"
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
Credentials({
credentials: {
email: { label: "Email", type: "text" },
password: { label: "Password", type: "password" },
},
authorize: async (credentials) => {
let user = null
const { email, password } = await signInSchema.parseAsync(credentials)
user = await getUserByEmail(email, password)
if (!user) {
throw new Error("User not found.")
}
return user
},
}),
],
})