I just found issue on sails-auth/api/services/passport.js on passport.connect for existing user/passport. the issue is on line 134 for saving passport and return user record.
On sails 0.12.14 the callback for the promise is no longer has parameter model in it, instead it has parameter error. so the old code:
is no longer works because the promise resolve function with parameter error:
return passport.save() .then(function (err) {
for this old code, the passport that necessary use to return the passport user always undefined since the save is success and no error returned. That the first issue on saving passport, the second one is on line 138 to return associated user within the passport:
first issue is that passport.user is identity number when auto populate flag not set to true. if we enable the populate flag to true then all models that has association in it will be auto populate, it can slow down the API. for anyone who disable the populate flag to false we need to treat the passport.user as the user identity not user entity. It's good to assume that anyone who use sails-auth module set their sails model config populate flag to default (e.g. False). The second issue with the code is that findOne function required criteria object and not support identity value (number), the code need to change into:
this code will work and return user associated with the passport if exists. I have test the changes on my local and the result it fix issue when I login with existing passport (if I use the old code I got error: "cannot access User of undefined").
I just found issue on sails-auth/api/services/passport.js on passport.connect for existing user/passport. the issue is on line 134 for saving passport and return user record.
On sails 0.12.14 the callback for the promise is no longer has parameter model in it, instead it has parameter error. so the old code:
return passport.save() .then(function (passport) {
is no longer works because the promise resolve function with parameter error:
return passport.save() .then(function (err) {
for this old code, the passport that necessary use to return the passport user always undefined since the save is success and no error returned. That the first issue on saving passport, the second one is on line 138 to return associated user within the passport:
return sails.models.user.findOne(passport.user.id);
first issue is that passport.user is identity number when auto populate flag not set to true. if we enable the populate flag to true then all models that has association in it will be auto populate, it can slow down the API. for anyone who disable the populate flag to false we need to treat the passport.user as the user identity not user entity. It's good to assume that anyone who use sails-auth module set their sails model config populate flag to default (e.g. False). The second issue with the code is that findOne function required criteria object and not support identity value (number), the code need to change into:
return sails.models.user.findOne({id: passport.user});
this code will work and return user associated with the passport if exists. I have test the changes on my local and the result it fix issue when I login with existing passport (if I use the old code I got error: "cannot access User of undefined").
passport-fix.txt