Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In node.js why does passport session stop formidable from triggering 'file' events?

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?

like image 247
Marwan Roushdy Avatar asked Jan 23 '13 12:01

Marwan Roushdy


People also ask

How does Nodejs passport work?

Passport is a popular, modular authentication middleware for Node. js applications. With it, authentication can be easily integrated into any Node- and Express-based app. The Passport library provides more than 500 authentication mechanisms, including OAuth, JWT, and simple username and password based authentication.

What is session in passport js?

This series of requests and responses, each associated with the same user, is known as a session. HTTP is a stateless protocol, meaning that each request to an application can be understood in isolation - without any context from previous requests.

What does done do in passport js?

This is possible with the help of done() function. It is an internal passport js function that takes care of supplying user credentials after user is authenticated successfully. This function attaches the email id to the request object so that it is available on the callback url as "req. user".


1 Answers

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

like image 65
Rob Riddle Avatar answered Oct 22 '22 20:10

Rob Riddle