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?
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.
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.
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".
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With