bnoguchi/everyauth — Issue #105: Everyauth middleware + Formidable/Connect-form modules? 
Author: felixchan
Created: 2011-10-26 00:48:34+00:00
State: open

Hi

I tried doing form uploads with connect-form, but I get this error:
```
Error: parser error, 0 of 1448 bytes parsed
at IncomingForm.write (/home/myuser/myproject/node_modules/connect-form/node_modules/formidable/lib/incoming_form.js:141:17)
at IncomingMessage. (/home/myuser/myproject/node_modules/connect-form/node_modules/formidable/lib/incoming_form.js:91:12)
at IncomingMessage.emit (events.js:64:17)
at HTTPParser.onBody (http.js:121:23)
at Socket.ondata (http.js:1008:22)
at Socket._onReadable (net.js:682:27)
at IOWatcher.onReadable [as callback] (net.js:177:10)
```

It seems that, after contacting the author, you have to "pause" and "resume" the request during the middleware.

I manually added the "pause" and "resume" in here:

```
function fetchUserFromSession (req, res, next) {
var sess = req.session
, auth = sess && sess.auth
, everymodule, findUser;
if (!auth) return next();
if (!auth.userId) return next();
everymodule = everyauth.everymodule;
if (!everymodule._findUserById) return next();
var pause = utils.pause(req);
everymodule._findUserById(auth.userId, function (err, user) {
if (err) throw err; // TODO Leverage everyauth's error handling
if (user) req.user = user;
next();
pause.resume();
});
}
```
After doing this, it seems to work.

Is this the right way to do it? Is there any alternative solution?