Open fenichelar opened 8 years ago
I was also facing the same issue, it seems like the sails version 12.1 is not compatible with sails-auth 2.1.3.
According to the code it is looking for promise to return from the passport.save() but modifying it to callback function it works.
change node_modules/sails-auth/dist/api/services/passport.js:134:54
from
return passport.save().then(function (passport) {
to
return passport.save(function (err, passport) {
works just fine.
Let's hope this fix will be implemented in future versions.
Edit: It does not seems to work, again it is throwing an error
warn: undefined 'TypeError: undefined is not a function\n at /home/vats/Projects/GetSportive_comm/node_modules/sails-auth/dist/api/services/passport.js:136:14\n at wrapper (/home/vats/npm/lib/node_modules/sails/node_modules/lodash/index.js:3592:19)\n at applyInOriginalCtx (/home/vats/npm/lib/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:417:80)\n at wrappedCallback (/home/vats/npm/lib/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:320:18)\n at callback.success (/home/vats/npm/lib/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/normalize.js:33:31)\n at _switch (/home/vats/npm/lib/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/factory.js:58:28)\n at returnResults (/home/vats/npm/lib/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js:180:9)\n at /home/vats/npm/lib/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js:86:16\n at /home/vats/npm/lib/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:83:7\nFrom previous event:\n at Deferred.then (/home/vats/npm/lib/node_modules/sails/node_modules/waterline/lib/waterline/query/deferred.js:505:27)\n at Authenticator.passport.connect (/home/vats/Projects/GetSportive_comm/node_modules/sails-auth/dist/api/services/passport.js:108:6)\n at Strategy.module.exports [as _verify] (/home/vats/Projects/GetSportive_comm/node_modules/sails-auth/dist/api/services/protocols/oauth2.js:36:27)\n at /home/vats/Projects/GetSportive_comm/node_modules/passport-facebook/node_modules/passport-oauth2/lib/strategy.js:183:24\n at /home/vats/Projects/GetSportive_comm/node_modules/passport-facebook/lib/strategy.js:181:5\n at passBackControl (/home/vats/Projects/GetSportive_comm/node_modules/passport-facebook/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:125:9)\n at IncomingMessage.<anonymous> (/home/vats/Projects/GetSportive_comm/node_modules/passport-facebook/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7)\n at IncomingMessage.emit (events.js:129:20)\n at _stream_readable.js:908:16\n at process._tickDomainCallback (node.js:381:11)' [TypeError: undefined is not a function]
I am sure passport.save() is returning an undefined value for passport but why? I checked passport is defined and is a valid object before doing save.
My next try is to handle the failed promise after save.
Edit: Save no longer returns the second argument as mentioned in upgrade to v0.12.1 guide http://sailsjs.org/version-notes/0point12-migration-guide
I am hoping a compatibility update must on its way for this package and we will get the stable version soon, meanwhile I have found a workaround by removing the passport from then function and also passport.user.id should be changed to passport.user
there is already a pull request open with exact same solution https://github.com/tjwebb/sails-auth/pull/129/files
I am having an issue with Google OAuth2. I
GET
/auth/google
and authenticate. I thenGET
/logout
and logout. If I thenGET
/auth/google
again, I don't authenticate and receive the following error:warn: undefined 'TypeError: Cannot read property \'user\' of undefined\n at /Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails-auth/dist/api/services/passport.js:134:54\n at processImmediate [as _immediateCallback] (timers.js:367:17)\nFrom previous event:\n at /Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails-auth/dist/api/services/passport.js:131:34\n at wrapper (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/lodash/index.js:3592:19)\n at applyInOriginalCtx (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:417:80)\n at wrappedCallback (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:320:18)\n at callback.success (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/normalize.js:33:31)\n at _switch (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/node_modules/switchback/lib/factory.js:58:28)\n at returnResults (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js:180:9)\n at /Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js:86:16\n at /Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:83:7\n at /Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:52:16\n at Object.async.forEachOf.async.eachOf (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:236:30)\n at Object.async.forEach.async.each (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:209:22)\nFrom previous event:\n at Deferred.then (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails/node_modules/waterline/lib/waterline/query/deferred.js:505:27)\n at Authenticator.passport.connect (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails-auth/dist/api/services/passport.js:108:6)\n at Strategy.module.exports [as _verify] (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/sails-auth/dist/api/services/protocols/oauth2.js:36:27)\n at /Users/Alec/Sites/GTFriender-Web-Server/node_modules/passport-google-oauth/node_modules/passport-google-oauth20/node_modules/passport-oauth2/lib/strategy.js:183:24\n at /Users/Alec/Sites/GTFriender-Web-Server/node_modules/passport-google-oauth/node_modules/passport-google-oauth20/lib/strategy.js:122:5\n at passBackControl (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/passport-google-oauth/node_modules/passport-google-oauth20/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:125:9)\n at IncomingMessage.<anonymous> (/Users/Alec/Sites/GTFriender-Web-Server/node_modules/passport-google-oauth/node_modules/passport-google-oauth20/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7)\n at IncomingMessage.emit (events.js:129:20)\n at _stream_readable.js:908:16\n at process._tickDomainCallback (node.js:381:11)' [TypeError: Cannot read property 'user' of undefined]
It only happens if I login, then logout, then login again. Should I not use /auth/google for login? Thanks.