Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with sails 0.12.14 #167

Open
ariston1983 opened this issue Jan 29, 2018 · 0 comments
Open

issue with sails 0.12.14 #167

ariston1983 opened this issue Jan 29, 2018 · 0 comments

Comments

@ariston1983
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant