-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
48 lines (43 loc) · 1.19 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import NextAuth from 'next-auth';
import Credentials from 'next-auth/providers/credentials';
import db from '@/lib/db';
import { compareSync } from 'bcrypt-ts';
export const {
handlers: { GET, POST },
auth,
signIn,
signOut
} = NextAuth({
providers: [Credentials({
credentials: {
email: {
label: 'Email',
type: 'email'
},
password: {
label: 'Password',
type: 'password'
}
},
async authorize(credentials) {
const email = credentials.email as string
const password = credentials.password as string
if (!email || !password) {
return null
}
const user = await db.users.findUnique({
where: {
email: email
}
})
if (!user) {
return null
}
const isValidPassword = compareSync(password, user.password ?? '')
if (!isValidPassword) {
return null
}
return { id: user.id, name: user.name, email: user.email }
}
})],
});