Skip to content

Instantly share code, notes, and snippets.

@keithics
Created February 24, 2016 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithics/9821d3fab905fe615ef9 to your computer and use it in GitHub Desktop.
Save keithics/9821d3fab905fe615ef9 to your computer and use it in GitHub Desktop.
Token Middleware and Routes Sample
//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