trailsjs / sails-auth

Passport-based User Authentication system for sails.js applications. Designed to work well with the sails-permissions module.
https://www.npmjs.org/package/sails-auth
MIT License
266 stars 141 forks source link

Sails auth now throwing sails.services.passport.loadStrategies() undefined error. #70

Open Rohaan-I opened 9 years ago

Rohaan-I commented 9 years ago

I was building an app using sailsjs and after week ago it was working fine but right now I'm getting this error. I did'nt change anything. The stacktrace is given below:-

/home/redbuffer/my_stuff/apps/AfterEidApp1/node_modules/sails-auth/api/hooks/sails-auth.js:4 sails.services.passport.loadStrategies(); ^ TypeError: Cannot read property 'loadStrategies' of undefined at Hook.initialize (/home/redbuffer/my_stuff/apps/AfterEidApp1/node_modules/sails-auth/api/hooks/sails-auth.js:4:30) at Hook.bound as initialize at /home/redbuffer/my_stuff/apps/AfterEidApp1/node_modules/sails/lib/hooks/index.js:78:14 at /home/redbuffer/my_stuff/apps/AfterEidApp1/node_modules/sails/node_modules/async/lib/async.js:451:17 at /home/redbuffer/my_stuff/apps/AfterEidApp1/node_modules/sails/node_modules/async/lib/async.js:441:17 at _each (/home/redbuffer/my_stuff/apps/AfterEidApp1/node_modules/sails/node_modules/async/lib/async.js:46:13) at Immediate.taskComplete (/home/redbuffer/my_stuff/apps/AfterEidApp1/node_modules/sails/node_modules/async/lib/async.js:440:13) at processImmediate as _immediateCallback

peazz commented 9 years ago

I have just installed and am also getting this error.

mkaag commented 9 years ago

+1

sachanganesh commented 9 years ago

+1

manuel140 commented 9 years ago

+1

GiantCrocodile commented 9 years ago
\node_modules\sails-auth\api\hooks\sails-auth.js:4
      sails.services.passport.loadStrategies();
                             ^
TypeError: Cannot read property 'loadStrategies' of undefined
    at Hook.initialize (\node_modules\sails-auth\api\hooks\sails-auth.js:4:30)
    at Hook.bound [as initialize] (\node_modules\lodash\dist\lodash.js:729:21)
    at \node_modules\sails\lib\hooks\index.js:75:14
    at \node_modules\sails\node_modules\async\lib\async.js:451:17
    at \node_modules\sails\node_modules\async\lib\async.js:441:17
    at _each (\node_modules\sails\node_modules\async\lib\async.js:46:13)
    at Immediate.taskComplete (\node_modules\sails\node_modules\async\lib\async.js:440:13)
    at processImmediate [as _immediateCallback] (timers.js:374:17)

+1 happening with sails latest stable

mariantatarau commented 9 years ago

i have the same issue

tjwebb commented 9 years ago

What version of sails are you guys running?

manuel140 commented 9 years ago

@tjwebb I'm running v0.11.2

My Error Message:

/home/xxx/xxx/node_modules/sails-auth/api/hooks/sails-auth.js:4
      sails.services.passport.loadStrategies();
                             ^
TypeError: Cannot read property 'loadStrategies' of undefined
    at Hook.initialize (/home/xxx/xxx/node_modules/sails-auth/api/hooks/sails-auth.js:4:30)
    at Hook.bound [as initialize] (/usr/local/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
    at /usr/local/lib/node_modules/sails/lib/hooks/index.js:75:14
    at /usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:451:17
    at /usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:441:17
    at _each (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:46:13)
    at Immediate.taskComplete (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:440:13)
    at processImmediate [as _immediateCallback] (timers.js:367:17)
GiantCrocodile commented 9 years ago

Same version as manuel140 on Windows 10 64-bit @tjwebb.

sachanganesh commented 9 years ago

@tjwebb I'm in the same boat; I'm running the same version as manuel140 and GiantCrocodile on Ubuntu.

tjwebb commented 9 years ago

And this is happening on sails-auth 1.3.1?

2c2c commented 9 years ago
{ Desktop }  » mkdir test                                                         /cygdrive/c/Users/2c/Desktop
{ Desktop }  » cd test                                                            /cygdrive/c/Users/2c/Desktop
{ test }  » sails new                                                        /cygdrive/c/Users/2c/Desktop/test
info: Created a new Sails app `test`!
{ test }  » sails lift                                                       /cygdrive/c/Users/2c/Desktop/test

info: Starting app...

info:
info:                .-..-.
info:
info:    Sails              <|    .-..-.
info:    v0.11.0             |\
info:                       /|.\
info:                      / || \
info:                    ,'  |'  \
info:                 .-'.-==|/_--'
info:                 `--'-------'
info:    __---___--___---___--___---___--___
info:  ____---___--___---___--___---___--___-__
info:
info: Server lifted in `C:\Users\2c\Desktop\test`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press <CTRL> + C at any time.

debug: --------------------------------------------------------
debug: :: Tue Sep 29 2015 22:22:26 GMT-0700 (Pacific Daylight Time)

debug: Environment : development
debug: Port        : 1337
debug: --------------------------------------------------------

{ test }  » npm i sails-auth --save                                      /cygdrive/c/Users/2c/Desktop/test 130
sails-auth@1.3.1 node_modules\sails-auth
├── passport-twitter@1.0.3 (xtraverse@0.1.0, passport-oauth1@1.0.1)
├── passport-facebook@1.0.3 (passport-oauth2@1.1.2)
└── passport-google-oauth@0.2.0 (pkginfo@0.3.0, passport-oauth@1.0.0)
{ test }  » sails lift                                                       /cygdrive/c/Users/2c/Desktop/test

info: Starting app...

C:\Users\2c\Desktop\test\node_modules\sails-auth\api\hooks\sails-auth.js:4
      sails.services.passport.loadStrategies();
                             ^
TypeError: Cannot read property 'loadStrategies' of undefined
    at Hook.initialize (C:\Users\2c\Desktop\test\node_modules\sails-auth\api\hooks\sails-auth.js:4:30)
    at Hook.bound [as initialize] (C:\Users\2c\AppData\Roaming\npm\node_modules\sails\node_modules\lodash\dist\lodash.js:729:21)
    at C:\Users\2c\AppData\Roaming\npm\node_modules\sails\lib\hooks\index.js:75:14
    at C:\Users\2c\AppData\Roaming\npm\node_modules\sails\node_modules\async\lib\async.js:451:17
    at C:\Users\2c\AppData\Roaming\npm\node_modules\sails\node_modules\async\lib\async.js:441:17
    at _each (C:\Users\2c\AppData\Roaming\npm\node_modules\sails\node_modules\async\lib\async.js:46:13)
    at Immediate.taskComplete (C:\Users\2c\AppData\Roaming\npm\node_modules\sails\node_modules\async\lib\async.js:440:13)
    at processImmediate [as _immediateCallback] (timers.js:367:17)
{ test }  »                                                                /cygdrive/c/Users/2c/Desktop/test 1

edit: dies on sails 11.2 as well

sunnycmf commented 9 years ago

:+1: I run into same problem on Sails version: 0.11.2, sails-auth 1.3.1

BipinBhandari commented 9 years ago

+1

bmatto commented 9 years ago

+1

ouadi commented 9 years ago

I'm running into the same issue. Details of my context:

To reproduce the issue:

info: Starting app...

/home/.../webapp/node_modules/sails-auth/api/hooks/sails-auth.js:4
      sails.services.passport.loadStrategies();
                             ^
TypeError: Cannot read property 'loadStrategies' of undefined
  at Hook.initialize (/home/.../webapp/node_modules/sails-auth/api/hooks/sails-auth.js:4:30)
  at Hook.bound [as initialize] (/home/.../node-v0.12.7-linux-x64/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
  at /home/.../node-v0.12.7-linux-x64/lib/node_modules/sails/lib/hooks/index.js:75:14
  at /home/.../node-v0.12.7-linux-x64/lib/node_modules/sails/node_modules/async/lib/async.js:451:17
  at /home/.../node-v0.12.7-linux-x64/lib/node_modules/sails/node_modules/async/lib/async.js:441:17
  at _each (/home/.../node-v0.12.7-linux-x64/lib/node_modules/sails/node_modules/async/lib/async.js:46:13)
  at Immediate.taskComplete (/home/.../node-v0.12.7-linux-x64/lib/node_modules/sails/node_modules/async/lib/async.js:440:13)
  at processImmediate [as _immediateCallback] (timers.js:367:17)
ouadi commented 9 years ago

@tjwebb

As you might know, the issue is due to the fact that sails services are loaded after sails hooks in versions 0.11.0 and 0.11.2 that I have tested.

It is more logical that all components of a hook are loaded before the hook itself (which was assumed by the developer of the hook).

kddubb commented 9 years ago

+1

Does anyone have a workaround?

I have the same setup as @ouadi

ouadi commented 9 years ago

It looks like it is a 'hard to solve malfunction': the hook expects that its services have been loaded before it gets loaded itself, which is not the case. In addition, both Sails.js and sails-auth hook are far away from there latest release 1.11.2 and 1.3.1 respectively. So, I expect that the solution from sails.js team will take time.

Till then, I'm using now passport.js directly. People interested in this alternative can find its description here.

sunnycmf commented 9 years ago

@ouadi yup i also considering to use passports directly, but we may need to glue diff libraries by ourselves and also need to consider when to switch back to sails.

ouadi commented 9 years ago

I hope that our friends in sails team get quickly a time slot to solve this issue as it is a show stopper for two great extensions: sails-auth and sails-permission. They are doing a great job so far and I'm all hope that they will keep up on the same level of excellence.

ghost commented 9 years ago

I was just trying to start a fresh project and encountered this (My luck, the day I start...)

While this might not be an acceptable production work around, it got me developing: by uninstalling sails v0.11.2, and reinstalling sails@balderdashy/sails (which installs v12 rc), then in my project specifically installing sails-auth@2.1.1

kddubb commented 9 years ago

Thanks for the workaround @synaxin

fredericlefeurmou commented 9 years ago

+1

sunnypatel commented 8 years ago

@synaxin :+1:

tjwebb commented 8 years ago

We will try to address this soon. Thank you all for your support.

ronenteva commented 8 years ago

+1

sunnypatel commented 8 years ago

Not to throw this hardworking team under the bus, do appriciate their work, but I tried Waterlock and it works like a charm!

martinbeentjes commented 8 years ago

I experienced the same problem. After a bit of googling I found this solution. After editing my package.json and setting the version of sails-auth to 1.2.3 it fixes my problem.

muradaliyev commented 8 years ago

Another workaround you can try:

Create passport.js file under [project]\api\services and put this code inside: module.exports = require('sails-auth/api/services/passport');

dioptre commented 8 years ago

thanks @muradaliyev i tried them all and that did it! :)

Ps I had to do it in conjunction with repeating:

npm install sails-permissions sails-auth@^2 --save

In conjunction with:

https://github.com/tjwebb/sails-permissions/issues/181

muradaliyev commented 8 years ago

@dioptre, it looks like we need to repeat the same trick with sails-auth/api/services/authservice.js, If it is not already created with generator script.

It is responsible for the next=url parameter in login request (if you want to redirect browser after successful login)

matheuss commented 8 years ago

+1 for the issue and +1 for @muradaliyev's workaround! :)

YoleYu commented 8 years ago

specify sails-auth version to 2.1.1 in package.json can resolve this problem.

tnat1031 commented 8 years ago

thanks @YoleYu that worked for me

sergiyvoytovych commented 7 years ago

I had the same problems in one of my sails app repositories. I fixed it by installing a previous version of sails-auth.

npm install sails-auth@1.2.3

This fixed it for me. I also updated dependency reference for my package.json from

"sails-auth": "^1.0.10",

to

"sails-auth": "1.2.3",

After this I was able to lift with no problems. I created an issue report here: https://github.com/balderdashy/sails/issues/3385

Hope this helps.