在Passport + Express + Node

时间:2018-10-13 19:18:34

标签: node.js express passport.js

我正在尝试将护照与Google策略配合使用,但是我收到req.user的信息未定义。这是我的index.js:

...
// pass passport for configuration
require('./config/passport.js')(passport); 

//load all controllers and routes
load('controllers')
.then('routes')
.into(app);

//define port
const port = process.env.PORT || 3011;

// set views for error and 404 pages
app.set('views', __dirname + '/views');

var db_options = {
  host     : process.env.MYSQL_HOST,
  user     : process.env.MYSQL_USER,
  password : process.env.MYSQL_PASSWORD,
  database : process.env.MYSQL_DB
};

//connect with database
var connection = mysql.createConnection(db_options);
connection.connect();
var sessionStore = new mysqlStore({}, connection);

//set public folder
app.use(express.static(__dirname+'/public'));

app.use(flash()); // use connect-flash for flash messages stored in session

// read cookies (needed for auth)
app.use(cookieParser('abc')); 

// get information from html forms
app.use(bodyParser()); 

//set session
// app.set('trust proxy', 1); // trust first proxy
app.use(session({
  secret: 'abc',
  cookie: { maxAge: 3600000 },
    resave: true, 
    saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
..

我检查了this个问题,但没有一个解决方案。

0 个答案:

没有答案