Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

deserializeUser is called twice #83

Closed
1dot44mb opened this Issue · 2 comments

3 participants

@1dot44mb

After spending one day to solve the n calls to the deserializeUser middleware, (as mentioned in #14) now the problem is deserializeUser is called twice per request.

Here is my app.configure:

app.configure(function(){
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.use(express.static(__dirname + '/client/public'));

    app.use(express.cookieParser());
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(express.session({
            secret: "secret",
            key: 'express.sid',
            //store: store = persistance.store
        }));

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

Any idea or any directions will be useful. Thanks.

@plus-

Your page construction itself could be an explanation.

If it is built over multiple components which load via ajax, it could explain why you have still several calls

@jaredhanson
Owner

Passport only ever calls deserializeUser once per request, when restoring the session. The only line it invokes this function is here: https://github.com/jaredhanson/passport/blob/master/lib/passport/strategies/session.js#L41

If you're seeing multiple calls to this function, it is guaranteed to be a result of a different request, perhaps triggered by a single page (loading images, ajax requests as suggested by @plus- , etc.). My suggestion is to add some debugging middleware to the top of your stack so you can explicitly see the request flow:

app.use(function(req, res, next) {
  console.log('handling request for: ' + req.url);
  next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.