-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.ts
More file actions
53 lines (46 loc) · 1.45 KB
/
auth.ts
File metadata and controls
53 lines (46 loc) · 1.45 KB
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
import { NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import bcrypt from "bcrypt"
import { sql } from "@vercel/postgres";
const authOptions: NextAuthOptions = {
session: {
strategy: "jwt"
},
pages: {
signIn: "/login",
signOut: "/logout"
},
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {},
password: {}
},
async authorize(credentials, req) {
if (!credentials) return null;
const res = await sql`
SELECT * FROM users WHERE email=${credentials.email}
`
const user = res.rows[0];
const passOk = await bcrypt.compare(credentials.password || "", user.password);
if (passOk) {
return {
id: user.id,
name: user.name,
email: user.email
}
}
return null;
}
})
],
callbacks: {
async session({ session, token }) {
session.user = { ...session.user, id: token.sub || ""}
return session;
}
},
secret: process.env.NEXTAUTH_SECRET
}
export default authOptions