gpt4 book ai didi

serialization - Passport 反序列化被调用太多次

转载 作者:行者123 更新时间:2023-12-04 18:03:56 32 4
gpt4 key购买 nike

我不明白为什么我的反序列化方法被调用了这么多次。这是我的 server.js 文件

var express = require('express');
var app = express();

var passport = require('passport');
var bodyParser = require('body-parser');
var session = require('express-session');
var MongoSessionStore = require('connect-mongo/es5')(session);


// Local ENV ======================================================================

var env = require('./config/config.json')[app.get('env')];

// Mongo Database ======================================================================

var mongoInstance = require('./config/db.config.js');

mongoInstance.connection.on('open', function(){
console.log('connection works');
});

// Configuration ======================================================================

app.use(session({
secret: 'secretsarenofun', // Change this to anything else
resave: false,
saveUninitialized: true,
store: new MongoSessionStore({
mongooseConnection: mongoInstance.connection,
autoRemoveInterval: 60
})
}));

require('./config/passport.config.js')(passport, env, mongoInstance);

app.use(passport.initialize());
app.use(passport.session());

// Routes ======================================================================

var auth = require('./routes/auth.route')(app, passport);
var users = require('./routes/users.route')(passport);

// Middleware ======================================================================

app.use(express.static(__dirname + '/public'));
app.use('/users', users);
app.use('/auth', auth);

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());


// Launch ======================================================================

var server = app.listen(8000, function(){
console.log('The dagger flies at 8000');
});

var io = require('socket.io').listen(server);

require('./sockets')(io);

在我的 Passport 模块中,我设置了这个
module.exports = function(passport, env, db){
var request = require('request');
var OpenIDStrategy = require('passport-openid').Strategy;
var steamKey = 'test';
var User = require('../models/user.model');

var SteamStrategy = new OpenIDStrategy({
providerURL: 'http://steamcommunity.com/openid',
stateless: true,
returnURL: env.path+'/auth/openid/return',
realm: env.path,
},
function(identifier, done) {
var steamId = identifier.match(/\d+$/)[0];

return done(null, {
identifier: identifier,
steamId: identifier.match(/\d+$/)[0]
});
});

passport.use(SteamStrategy);

passport.serializeUser(function(user, done) {
done(null, user.identifier.match(/\d+$/)[0]);
});

// used to deserialize the user
passport.deserializeUser(function(identifier, done) {
console.log('this calls too many times');

//fetch
done(null, identifier);
});


};

当我在对反序列化函数调用进行身份验证后访问主页时,它应该调用了 8 次。

为什么是这样?我尝试移动 app.use(passport.initialize());
app.use(passport.session());有一些运气,但不完全。为什么会出现这种情况?

最佳答案

移动app.use(express.static(__dirname + '/public'))以上app.use(passport.initialize());

关于serialization - Passport 反序列化被调用太多次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36052739/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com