-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstratergies.js
35 lines (31 loc) · 934 Bytes
/
stratergies.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
const passport=require('passport')
const LocalStratergy=require('passport-local')
// const FacebookStratergy=require('passport-facebook')
// const GoogleStrategy=require('passport-google-oauth20')
const { connectdb }=require('./database/db.js')
passport.use(new LocalStratergy({
usernameField: 'email'
},(username, password, done) => {
connectdb('hackTIET')
.then(db => db.collection('users').find({ email: username }))
.then(user => user.toArray())
.then((user) => {
if(!user) {
return done(new Error('username invalid'))
}
if(user[0].password != password) {
return done(null, false)
}
done(null, user)
})
.catch(done)
}
)
);
passport.serializeUser((user, done) => {
done(null, user)
})
passport.deserializeUser((user, done) => {
done(null, user)
})
module.exports = passport