node.js - express router middleware: reference error "req is not defined" -


im working middleware authenticate token, probolem isn't snippet, problem stars when instantiate function.

there code:

router.use(authrequirer(req, res, next)); 

sure, here routing file:

let router = express.router();  // middleware import authrequirer '../util/authrequirer';  // controllers import authctrl '../controllers/authctrl'; import userctrl '../controllers/userctrl';  let authctrl = new authctrl(); let userctrl = new userctrl();  router.get('/', (req, res) => {   res.json({ message: "hey, im working" }); });  // login, register, setup admin router.get('/setup'    , authctrl.setup); router.post('/register', authctrl.register); router.post('/login'   , authctrl.login);  // autenticacion requerida router.use(authrequirer(req, res, next));  router.route('/users')   .get(userctrl.getall)   .post(userctrl.create);  router.route('/users/:username')   .get(userctrl.getone)   .put(userctrl.edit)   .delete(userctrl.delete);  export default router; 

i think don't out of normal, when run code, throws me following trace:

/home/nano/dev/omgfriki-api/app/routes/apiroutes.js:44 router.use((0, _utilauthrequirer2['default'])(req, res, next));                                               ^ referenceerror: req not defined 

why req isn't defined? far understand, defined when call router.

anyway, i'm using babel require hook compile things, 90% it's not problem.

instead of invoking authrequirer function variables req, res, , next don't exist yet:

router.use(authrequirer(req, res, next));

you should pass function:

router.use(authrequirer);

because use method 1 going invoke authrequirer function passing req, res, , next parameters.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -