// keys.js
module.exports = {
mongoURI: "",
secretOrKey: "secret"
}
const keys = require("../../config/keys");
router.post("/login", (req, res) => {
const email = req.body.email;
const password = req.body.password;
User.findOne({ email }).then(user => {
if (!user) {
return res.status(404).json({ email: "!" })
}
// Load hash from your password DB.
bcrypt.compare(password, user.password, (err, isMatch)=>{
if(isMatch){
const rule = {id:user.id,name:user.name};
jwt.sign({rule, keys.secretOrKey, {expiresIn:3600}, (err,token)=>{
if(err)throw err;
res.json({
success:true,
token:"partiny"+token
});
}});
res.json({msg:"success"});
}else{
return res.status(400).json({password:""});
}
});
})
})