In node.js why does passport session stop formidab

2019-02-03 23:08发布

问题:

In my app I am only using

app.use(express.json());
app.use(express.urlencoded());

and not

app.use(express.bodyParser());

so that I can manually parse file uploads. It seems that this line

app.use(passport.session());

stops formidable from triggering file events:

form.on('file', function(name, file) {
  //never called
});

How can I use passport session and not clash with formidable file event?

回答1:

Looks like they've added a way to fix this. Using app.use(passport.session({pauseStream: true})); instead will prevent async deserializations from breaking some middleware.

Source: https://github.com/jaredhanson/passport/pull/106



回答2:

The passport.session() method calls your passport.deserializeUser(), which itself usually makes a database call to fetch the user. This database call delays the execution of code that starts listening to the incoming data. That is, the data arrives while nobody is listening for it.