-
Notifications
You must be signed in to change notification settings - Fork 3
/
setuppassport.js
61 lines (52 loc) · 1.18 KB
/
setuppassport.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const passport = require('passport')
const LocalStrategy = require('passport-local').Strategy
const { Users } = require('./db')
passport.use('users', new LocalStrategy((username, password, done) => {
Users.findOne({
where: {
username,
}
})
.then((user) => {
if (!user) {
return done(new Error('Username invalid'))
}
if (user.password != password) {
return done(null, false)
}
done(null, user)
})
.catch(done)
})
)
// passport.use('admins', new LocalStrategy((username, password, done) => {
// Admins.findOne({
// where: {
// username,
// }
// })
// .then((admin) => {
// if (!admin) {
// return done(new Error('Username invalid'))
// }
// if (admin.password != password) {
// return done(null, false)
// }
// done(null, admin)
// })
// .catch(done)
// })
// )
passport.serializeUser((user, done) => {
done(null, user.id)
})
passport.deserializeUser((userId, done) => {
Users.findOne({
where: {
id: userId
}
})
.then((user) => done(null, user))
.catch(done)
})
module.exports = passport