-
Notifications
You must be signed in to change notification settings - Fork 0
/
passport.config.js
32 lines (31 loc) · 956 Bytes
/
passport.config.js
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
import { Strategy } from "passport-local";
import User from "./models/user.model.js";
import * as dotenv from "dotenv";
dotenv.config();
import passport from "passport";
const authenticateAdmin = async (email, password, done) => {
if (
email === process.env.ADMIN_EMAIL &&
password === process.env.ADMIN_PASSWORD
) {
return done(null, "ADMIN");
} else {
return done(null, false, { message: "Password incorrect" });
}
};
passport.use(
"admin",
new Strategy({ usernameField: "username" }, authenticateAdmin)
);
passport.use("user", User.createStrategy());
passport.serializeUser((user, done) => {
if (user === "ADMIN") {
return done(null, user);
} else return User.serializeUser()(user, done);
});
passport.deserializeUser((user, done) => {
if (user === "ADMIN") {
return done(null, user);
} else return User.deserializeUser()(user, done);
});
export default passport;