everyauth icon indicating copy to clipboard operation
everyauth copied to clipboard

Express autodetection doesn't work properly

Open aadamowski opened this issue 13 years ago • 11 comments

It seems that the approach for Express autodetection is by patching the connect's HTTPServer use() function in memory:

https://github.com/bnoguchi/everyauth/commit/b854bc5b3ea9709305a8cb7e90a1870600d86fa0#index.js

For some reason this doesn't work in my application, which uses everyauth indirectly through mongoose-auth (don't know if that's relevant since mongoose-auth clearly delegates middleware() and helpExpress() function calls without interfering).

My app hooks up everyauth this way:

config.app.use(mongooseAuth.middleware());

After adding some debug statements to everyauth/index.js, I've determined that everyauth's middleware() function gets run, but the replaced connect use() implementation isn't. Probably because, in my case, use() call happens (begins) before everyauth middleware() patches it.

Besides, the fact that everyauth middleware() can potentially be called by connect's methods and then itself reaches to connect's method (and overrides its implementation - regardless of whether their code is compatible or not!) creates a cyclic dependency between everyauth and connect.

In general, this causes real problems and is an example of:

bad code smells:

  • inappropriate intimacy (a class that has dependencies on implementation details of another class)
  • cyclic dependency

violations of at least 2 [SOLID](http://en.wikipedia.org/wiki/Solid_(object-oriented_design)) principles:

All that in the name of saving the programmer from making a single function call (helpExpress()), and with a price that he cannot decide anymore about the moment when it is performed.

I vote for the revert of commit b854bc5b3ea9709305a8cb7e90a1870600d86fa0 and bringing back the helpExpress() function, which has worked just fine.

aadamowski avatar Aug 11 '12 22:08 aadamowski

I'm in the exact same situation and my app doesn't work anymore since the update. Is there a workaround so I could stay with the master branch ?

paztek avatar Aug 13 '12 12:08 paztek

Definitely agree. I'm in the same situation as well.

dluces avatar Aug 14 '12 15:08 dluces

@aadamowski Have you tried using this branch instead? https://github.com/bnoguchi/everyauth/tree/express3 It is working for me (after updating to Express3)

dluces avatar Aug 16 '12 22:08 dluces

I am in the same situation and agree with the course of action specified in this pull request.

yzapuchlak avatar Aug 17 '12 20:08 yzapuchlak

+1

gaarf avatar Aug 21 '12 00:08 gaarf

@dluces I didn't, unfortunately I don't currently have time to migrate my app to Express 3.

aadamowski avatar Aug 21 '12 00:08 aadamowski

Same situation. Backed out of mongoose_auth, and am implementing db logic myself because of this issue.

stefaneg avatar Aug 26 '12 10:08 stefaneg

Has anyone acknowledged or reviewed the pull requests to revert prior changes? I have the same issues as above.

mcfazeli avatar Aug 30 '12 19:08 mcfazeli

+1. same issues here, at east give us back the helpExpress method to do what it once did.

tregusti avatar Oct 07 '12 16:10 tregusti

I am seeing the same problem. Is there any recent news on this?

joscha avatar Dec 05 '12 14:12 joscha

+1

justinwalsh avatar Mar 12 '13 00:03 justinwalsh