Thursday 8 February 2018

Beginner Problem with Express Router

Hey guys, I have tried for a while now but I just can't find the problem. I have set up a couple of routes using express router and want to put a simple authentication middleware in front of them. It works for a get request on route /search/player but post request ont he same route just ignores the middleware. Here is my code:auth/auth.js:module.exports = function (req, res, next) { if (req.user) return next(); else return res.render('login', { message: "You must be logged in for this." }); } routes/search.js:var express = require('express'); var router = express.Router(); var auth = require('../auth/auth'); var search_controller = require('../controllers/searchController'); router.get('/player', auth, search_controller.search_player_get); router.post('/player', auth, search_controller.search_player_post); [...] module.exports = router; I hope this kind of post is allowed in here. If not, let me know.

Submitted February 08, 2018 at 03:41PM by -jFk-

No comments:

Post a Comment