-
Notifications
You must be signed in to change notification settings - Fork 0
/
passport-config.js
40 lines (36 loc) · 1.17 KB
/
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
33
34
35
36
37
38
39
40
const LocalStrategy = require("passport-local").Strategy;
const server = require("./models/server");
const bcrypt = require("bcrypt");
const passport = require("passport");
const sobj = new server();
passport.use(
new LocalStrategy(
{ usernameField: "email" },
async (email, password, done) => {
try {
const user = await sobj.getEmail(email);
if (user == null) {
return done(null, false,"No user found with that email");
}
if (bcrypt.compareSync(password, user.Password)) {
return done(null, user);
} else {
return done(null, false,"Incorrect password");
}
} catch (error) {
return done(error);
}
}
)
);
passport.serializeUser((user, done) => {
done(null, user.id); // Assuming user has an 'id' property
});
passport.deserializeUser(async (id, done) => {
try {
const user = await sobj.getUserById(id); // Implement this method in your server class
done(null, user);
} catch (error) {
done(error);
}
});