diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/middleware.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/server/lib/middleware.js b/server/lib/middleware.js new file mode 100644 index 0000000..735fddb --- /dev/null +++ b/server/lib/middleware.js @@ -0,0 +1,31 @@ +const passport = require('passport'); + +const multer = require('multer'); +const uuid = require('uuid'); +const path = require('path'); + + +const isAuth = passport.authenticate('jwt', {session: false}); +const isAdmin = (req, res, next) => { + if (!req.user.admin) + res.status(401).json({status: "You need to be an administrator!"}); + else next(); +} + + +const multerStorage = multer.diskStorage({ + destination: (req, file, cb) => { + cb(null, "uploads/"); + }, + filename: (req, file, cb) => { + cb(null, uuid.v4() + path.extname(file.originalname)); + } +}); +const upload = multer({storage: multerStorage}); + + +module.exports = { + isAuth, + isAdmin, + upload +}; |