'use strict'; const passport = require('passport'); const httpStatus = require('http-status'); const compose = require('../helpers/middleware.helper'); const isRegisteredUserEmail = passport.authenticate('local-email', { session: false }); const isRegisteredUserPhone = passport.authenticate('local-phone', { session: false }); const isLoggedUser = passport.authenticate('jwt', { session: false }); const isAdministratorUser = compose([isLoggedUser, (req, res, next) => { const user = req.user; if (user.role >= 8) { next(); } else { return res.status(httpStatus.UNAUTHORIZED).send('UNAUTHORIZED'); } } ]); module.exports = { isRegisteredUserEmail, isRegisteredUserPhone, isLoggedUser, isAdministratorUser };