routes - How Can I Manage Session Data in Node.js Without Using the Request Scope? -
i've been experimenting several flavors of session management in node.js: node-session, express-session, etc. these configured in app.js, , implemented @ request level (e.g., req.session) in routes.
to use session management say, check visitor has authenticated, need perform check (e.g., req.session.isloggedin == true) on each of routes enforce login access. here's example:
router.get('/', function(req, res) { if (req.session.status == undefined) { res.redirect('/login'); } else { res.render('index', { pagetitle: 'index', pageid: 'index' }); } }); that means each .get() , .post() have check. work, there way can write once somehwere, in app.js, cover requests?
the express middleware you're looking for, please see http://expressjs.com/en/guide/using-middleware.html
Comments
Post a Comment