use local findOrCreate instead of User.findOrCreate when creating accounts - #12
use local findOrCreate instead of User.findOrCreate when creating accounts#12dpkirchner wants to merge 1 commit into
Conversation
|
Expected flow was reimplement findOrCreate, so, this may break backwards compatibility. |
|
What do you suggest? I couldn't get the original code to call user.js's |
|
Isn't User.findOrCreate = ... in user.js working? On Tue, May 7, 2013 at 6:55 PM, David Kirchner notifications@github.comwrote:
|
|
It wasn't working, no. I may be doing it wrong, though. I created a user model (define('User', function() ...)) and can verify that it was being used. The "if (!u.findOrCreate)" test prevented overwriting the model's method, but removing that test wasn't enough. |
|
@therealdpk, are you implementing User.findOrCreate within the function being exported in app/models/user.js? module.exports = function (compound, User) { |
|
I was attempting to use the function that (from what I could tell) was On Thu, May 30, 2013 at 4:09 PM, peter-story notifications@github.comwrote:
David 'dpk' Kirchner |
|
Line 91: if (!u.findOrCreate) {u.findOrCreate = require('./user.js').findOrCreate;} So this is checking to see if you have the findOrCreate function in your user model. If you don't, then compound-passport loads its own function. However, JugglingDB comes with this function, so that base method will always be found and called. It seems that the design intended for users to implement their own findOrCreate function in app/models/user.js like I showed above. What I did was copy, paste, and edit the code from compound_passport/lib/users.js. |
|
@peter-story yep, it seems that this: if (!u.findOrCreate) {
u.findOrCreate = require('./user.js').findOrCreate;
}will never happened. So, I redefined |
From what I can tell the strategy modules, such as
google.js, expect to be callinglib/user.js'sfindOrCreatefunction, but instead they're calling the underlying modelfindOrCreate(from jugglingdb). This resulted in essentially empty rows being added to the database.I'm not sure if this is the best solution, but to work around this I renamed
findOrCreateinlib/user.js(and all references in strategies/*). Now the database (mongodb in this case) gets the correct information.