Created a middleware for requests that checks for a token in the Authentication field in the header and verifies that the token is valid for a user.
This commit is contained in:
11
seasoned_api/src/webserver/middleware/mustBeAuthenticated.js
Normal file
11
seasoned_api/src/webserver/middleware/mustBeAuthenticated.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const mustBeAuthenticated = (req, res, next) => {
|
||||
|
||||
if (req.loggedInUser === undefined) {
|
||||
return res.status(401).send({
|
||||
success: false,
|
||||
error: 'You must be logged in.',
|
||||
}); }
|
||||
return next();
|
||||
};
|
||||
|
||||
module.exports = mustBeAuthenticated;
|
||||
Reference in New Issue
Block a user