-
Notifications
You must be signed in to change notification settings - Fork 3
/
passport.js
36 lines (31 loc) · 948 Bytes
/
passport.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
const passport=require('passport')
const LocalStrategy=require('passport-local').Strategy
const Users=require('./models/tablesCreater').Users
const session=require('express-session')
passport.use(new LocalStrategy((username,password,done)=>{
//if(req.user===undefined) return done(null,false,{message:{NoSuchUser}})
{
Users.findOne({
where:{
username:username
}
}).then(reluser=>{
if(reluser==null){
return done(null,false,{message:'NoSuchUser'})
}
if(reluser.password!==password){
return done(null,false,{message:'WrongPassword'})
}
else{
return done(null,reluser,{message:'Successful'})
}
})
}
}))
passport.serializeUser((user,done)=>{
done(null,user)
})
passport.deserializeUser((user,done)=>{
done(null,user)
})
module.exports=passport