-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
31 lines (27 loc) · 932 Bytes
/
auth.js
File metadata and controls
31 lines (27 loc) · 932 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
30
31
const passport=require('passport');
const Localpassport=require('passport-local').Strategy;
const person = require('./models/person');
passport.use(new Localpassport(async function(USERNAME ,passward,done){
try{
// const us=USERNAME.para
console.log('Received credentials:', USERNAME, passward);
const dta=await person.findOne({USERNAME});
if(!dta){
console.log('Invalid username');
return done(null,false,{message:"Invalid username"});
}
const matchpassword= await dta.comparepassword(passward);
if (matchpassword) {
console.log('Authentication successful');
return done(null,dta);
} else {
console.log('Incorrect password');
return done(null,false,{message:"Incorret password"});
}
// next();
}catch(err){
console.log("authentication "+err);
return done(err);
}
}))
module.exports=passport;