2
當我在我的節點js +護照應用程序中打開任何url時,我有2個數據庫請求(可能是deserialze方法調用)。Passport反序列化每次請求兩次調用
我的日誌:
NEW QUERY____________________
SELECT * FROM users WHERE id=$1
[ '1' ]
GET/200 248ms - 829b
NEW QUERY____________________
SELECT * FROM users WHERE id=$1
[ '1' ]
GET /stylesheets/style.css 404 3ms
Deserializtation方法和中間件:
app.configure(function() {
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.session({
secret: "thisismysecretkey",
store: new RedisStore({ host: 'localhost', port: 6379, client: redisClient })
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
});
passport.serializeUser(function(user, done){
done(null, user.id);
});
passport.deserializeUser(function(id, done){
user.get(id, function(err, user){
done(err, user);
});
});
看起來這issue但它不是爲我工作。與護照
我有工作認證的js它看起來有點害怕:
exports.authenticate = function (req, res) {
var form = new multiparty.Form();
form.parse(req, function(err, fields) {
var userEmail = fields.email[0];
var userPassword = fields.password[0];
if (err) throw err;
userProvider.isBlockedEmail(userEmail, function(err, blocked) {
if (err) throw err;
if (blocked) {
res.send({error: true, description: 'you did too much attempts'});
} else {
userProvider.authenticate(userEmail, userPassword, function (err, user) {
if (err) throw err;
else if (user === undefined) res.send({error: true, description: 'wrong login or password'});
else if (user) {
req.login(user, function (err) {
if (err) throw err;
else if (user.banned === true) res.send({error: true, description: 'access denied'});
else {
userProvider.resetAttemptsCounter(userEmail, function(err) {
if (err) throw err;
res.send(req.user);
});
}
});
} else {
userProvider.checkAndBlock(userEmail, function(err, isBlocked, descriptions) {
if (err) throw err;
if (isBlocked) {
res.send({error: true, description: descriptions});
} else {
userProvider.increaseAttemptsCounter(userEmail, function(err) {
if (err) throw err;
res.send({error: true, description: 'wrong login or password'});
});
}
});
}
});
}
});
});
};
請幫我避免這種開銷。
看看我的更新請,不遺憾的是工作 –
** GET /stylesheets/style.css 404 3ms **好像我連接CSS但我不是。 –
@SlowHarry它必須來自*的地方* :) – robertklep