-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
29 lines (23 loc) · 735 Bytes
/
auth.js
File metadata and controls
29 lines (23 loc) · 735 Bytes
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
const passport=require('passport');
const LocalStrategy= require('passport-local').Strategy;
const person=require('./models/person')
passport.use(new LocalStrategy(async(USERNAME,PASSWORD,done)=>{
try
{
console.log('Received Credentials',USERNAME,PASSWORD);
const user= await person.findOne({username:USERNAME});
if(!user)
return done(null,false,{message:'Incorrect username'});
const isPasswordMatch= await user.comparePassword(PASSWORD)
if(isPasswordMatch)
{
return done(null,user)
}
else{
return done(null,false,{message:'Incorrect password'});
}
}catch(e){
return done(e)
}
}))
module.exports=passport;