Created
February 24, 2016 03:04
-
-
Save keithics/9821d3fab905fe615ef9 to your computer and use it in GitHub Desktop.
Token Middleware and Routes Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//route | |
app.route('/mobile/v2/updateuser') | |
.post(users.checkAuthMiddleWare,mobile.updateuser); | |
//middleware | |
exports.checkAuthMiddleWare = function(req, res,next) { | |
console.log(req.body); | |
User.findOne({username:req.body.username,token:req.body.token},function(err,user){ | |
if(user){ | |
next(); | |
}else if(!user && !err) { | |
return res.status(400).send({ | |
message: 'Error Authentication' | |
}); | |
}else{ | |
res.status(400).send(err); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment