Skip to content

Commit

Permalink
Upload middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadlockDruid committed Sep 25, 2018
1 parent 1b8cb10 commit 197f512
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions server/middleware/authenticate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { User } = require("./../models/user");

var authenticate = (res, res, next) => {
var token = req.header('x-auth');

User.findByToken(token).then((user) => {
if(!user) {
return Promise.reject();
}

req.user = user;
req.token = token;
next();
}).catch(e => {
res.status(400).send();
});
};

module.exports = { authenticate };

0 comments on commit 197f512

Please sign in to comment.