-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauth.ts
43 lines (42 loc) · 1.06 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
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import { PASSWORD_HASH, EMAIL } from "@/envs";
import * as bcrypt from "bcrypt";
export const {
auth,
handlers: { GET, POST },
signIn,
signOut,
} = NextAuth({
session: {
strategy: "jwt",
},
providers: [
CredentialsProvider({
credentials: {
email: {},
password: {},
},
async authorize(credentials) {
try {
if (credentials == null) return null;
const { email, password } = credentials;
if (email == null || password == null || email !== EMAIL) {
return null;
}
const isPasswordValid = await bcrypt.compare(
password as string,
PASSWORD_HASH!
);
console.log("🗝️🗝️Password validity: ", isPasswordValid);
if (!isPasswordValid) {
return null;
}
return { email: EMAIL, name: "Admin" };
} catch (error) {
throw error;
}
},
}),
],
});