-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.config.ts
More file actions
30 lines (28 loc) · 845 Bytes
/
auth.config.ts
File metadata and controls
30 lines (28 loc) · 845 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
import MongoStore from "connect-mongo";
import { AdminModel } from "./admin.schema.js";
import bcrypt from "bcrypt";
const authenticate = async (email: string, password: string) => {
const admin = await AdminModel.findOne({ email });
if (!admin) return null;
const isValidPassword = await bcrypt.compare(password, admin.hashedPassword);
if (!isValidPassword) return null;
return admin;
};
export const AuthOptions = {
auth: {
authenticate: authenticate,
cookieName: "adminjs",
cookiePassword: "sessionsecret",
},
session: (sessionStore: MongoStore) => ({
store: sessionStore,
resave: true,
saveUninitialized: true,
secret: "sessionsecret",
cookie: {
httpOnly: process.env.NODE_ENV === "production",
secure: process.env.NODE_ENV === "production",
},
name: "adminjs",
}),
};