I am doing a login page with passportjs and expressjs, everything looks ok on the form but when I tried to use the session I get an error and the page is not render. can someone give a little hint?
App.js
// Routes
var viewRoute = require('./routes/view'),
apiRoute = require('./routes/api'),
loginRoute = require('./routes/login'),
appRoute = require('./routes/main');
app.use('/',viewRoute);
app.use('/api',apiRoute);
app.use('/app',appRoute);
app.use('/login',loginRoute);
app.post('/login',passport.authenticate('local',{
failureRedirect: '/',
successRedirect: '/app'
}));
my Routes/Main.js
var express = require('express');
module.exports = (function(){
'use strict';
var appRoute = express.Router();
appRoute.get('/', function(req, res) {
if (req.session.passport.user === undefined) {
res.redirect('/login');
}
else { res.render('index'); }
});
return appRoute;
})();
I'm new with nodejs and I couldn't find anything related. Usually the example is just one single app.js
res.render
uses templating to render a page. It doesn't look like you set up a templating engine. The express website provides a brief intro on how to do this ( http://expressjs.com/guide/using-template-engines.html ). If you wish to not use a template, you should use another method such as res.send
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.