我試圖做這行node.js表示變量undefined?
router.post(「/登錄」,passport.authenticate ...)
和路由器是在我的目錄中的文件夾中的路由器。我已經將它作爲模塊導出,並在我的app.js文件中使用它。
在app.js我有我需要在這個順序:
var passport = require('passport');
var routes = require('./routes/index');
var users = require('./routes/users');
var User = require('./models/models.js')
所以不應路由能夠訪問的護照嗎?
這是我的路線/指數
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res) {
res.render('index', { title: 'Express' });
});
router.post('/login', passport.authenticate('local', {
successRedirect: '/home',
failureRedirect: '/login',
failureFlash: true
}));
router.get('/login', function(req, res, next) {
var errors = req.flash('error');
})
module.exports = router;
這是我app.js的開始
var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var passport = require('passport');
var routes = require('./routes/index');
var users = require('./routes/users');
var User = require('./models/models.js');
var PassportLocalStrategy = require('passport-local');
後您用來導出模塊的代碼。 – Michael
你有沒有試過'require(「./config/passport」)(護照);'? – royhowie
添加了代碼,沒有要求配置,因爲我沒有這樣的文件夾 – user3340037