mongoose-auth
mongoose-auth copied to clipboard
fix for everyauth3
This is a Fix for everyauth3.
Without it I get this error:
TypeError: Object #<Object> has no method 'User'
at module.exports.findUserById (/home/charles/Repositories/Nuage/node_modules/mongoose-auth/lib/modules/everymodule/everyauth.js:7:10)
at Object.fetchUserFromSession [as handle] (/home/charles/Repositories/Nuage/node_modules/mongoose-auth/node_modules/everyauth/index.js:99:13)
at next (/home/charles/Repositories/Nuage/node_modules/mongoose-auth/node_modules/everyauth/node_modules/connect/lib/http.js:204:15)
at Object.registerReqGettersAndMethods [as handle] (/home/charles/Repositories/Nuage/node_modules/mongoose-auth/node_modules/everyauth/index.js:75:9)
at next (/home/charles/Repositories/Nuage/node_modules/mongoose-auth/node_modules/everyauth/node_modules/connect/lib/http.js:204:15)
at HTTPServer.Server.handle (/home/charles/Repositories/Nuage/node_modules/mongoose-auth/node_modules/everyauth/node_modules/connect/lib/http.js:217:3)
at Object.Server.use.handle (/home/charles/Repositories/Nuage/node_modules/express/node_modules/connect/lib/http.js:106:14)
at next (/home/charles/Repositories/Nuage/node_modules/express/node_modules/connect/lib/http.js:204:15)
at store.get.next (/home/charles/Repositories/Nuage/node_modules/express/node_modules/connect/lib/middleware/session.js:322:9)
at /home/charles/Repositories/Nuage/node_modules/express/node_modules/connect/lib/middleware/session.js:341:9
I'm not sure if it makes sense but it works for me :p
Tests passed.
I've use this fix and it works but it is expected to work in express3?
This should indeed work, but what if my model is not called 'User'? In my case I've named it 'Account'. There IS a method in the everyauth definition in mongoose-auth options that specifies a User() function that returns the model. The problem is that the 'this' object should refer to the everyauth object, but instead it refers to the window object.
The only fix I have in mind is to pass the model or everyauth as a parameter to the function call.
I'm using this fix and it works for me.
Confirmed, it works. Thanks for sharing!
The second commit that was listed (edc2bd2) worked for me. Why not pull this fix into the main branch?