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

TypeError: Cannot read property 'id' of undefined new/app/config/passport.js:17:17 #4427

Open
SpaceG opened this issue May 29, 2018 · 9 comments
Labels
3rd party package repro please Could you reproduce this in a repository for us?

Comments

@SpaceG
Copy link

SpaceG commented May 29, 2018

Hello everbody,

After, i callback and comeback to the homepage, i get this error, with the ID settings. @17:17

this is my passport.js file. are someone here to give me a tip for this issue ?

this mean this ?

cb(null, user.id);

this is my full passport.js file :

const passport = require('passport'),
      LocalStrategy = require('passport-local').Strategy,

      GitHubStrategy = require('passport-github2').Strategy,
      TwitterStrategy = require('passport-twitter').Strategy,
      FacebookStrategy = require('passport-facebook').Strategy,

      shortid = require('shortid');
      generatePassword = require('password-generator');


      bcrypt = require('bcrypt');



passport.serializeUser(function(user, cb) {
  cb(null, user.id);
});
passport.deserializeUser(function(id, cb){
  User.findOne({id}, function(err, user) {
    cb(err, user);
  });
});


passport.use(new LocalStrategy({
    usernameField: 'email',
    passwordField: 'password'
  },
  function(email, password, done) {
    
    User.findOne({ email: email }, function (err, user) {
      if (err) { return done(err); }
      if (!user) {
        return done(null, false, { message: 'Incorrect email.' });
      }
     
      bcrypt.compare(password, user.password, function (err, res) {
          if (!res)
            return done(null, false, {
              message: 'Invalid Password'
            });
          var returnUser = {
            username: user.username,
            createdAt: user.createdAt,
            id: user.id
          };
          return done(null, returnUser, {
            message: 'Logged In Successfully'
          });
        });
    });
  }
));






// oAuth beginning here 


passport.use(new TwitterStrategy({
    consumerKey: 'YQKoiGgFsFcQRIKXrLqMW1RG0',
    consumerSecret: 'CjaYASh5raoV9RuGQmhh0VFp3o80YMyJn6OutB9HNZtasfm0FV',
    callbackURL: "http://localhost:1337/auth/twitter/callback"
  },

function(token, tokenSecret, profile, done) {
  User.findOrCreate(data, function(err, user) {
    if (err) { return done(err); }
    done(null, user);
  });
}
));




passport.use(new GitHubStrategy({
  clientID: '89d03b1f560e93d911be',
  clientSecret: 'b4ea5e9aad5e36d6bbb9f1e3a851575bb0fc2eaf',
  callbackURL: "http://localhost:1337/auth/github/callback"
},

function(token, tokenSecret, profile, done) {
User.findOrCreate(data, function(err, user) {
  if (err) { return done(err); }
  done(null, user);
});
}
));



passport.use(new FacebookStrategy({
  clientID: '169553873736123',
  clientSecret: '3dfef9e57f803b5879700a27d9ff81c3',
  callbackURL: "http://localhost:1337/auth/facebook/callback"
},

function(token, tokenSecret, profile, done) {
User.findOrCreate(data, function(err, user) {
  if (err) { return done(err); }
  done(null, user);
});
}
));

this case is my terminal section:

codes-Mac-mini:oauthy Kopie jh$ sails lift

 info: Starting app...

 info: ·• Auto-migrating...  (alter)
 info:    Hold tight, this could take a moment.
 info:  ✓ Auto-migration complete.

 info: 
 info:                .-..-.
 info: 
 info:    Sails              <|    .-..-.
 info:    v1.0.1              |\
 info:                       /|.\
 info:                      / || \
 info:                    ,'  |'  \
 info:                 .-'.-==|/_--'
 info:                 `--'-------' 
 info:    __---___--___---___--___---___--___
 info:  ____---___--___---___--___---___--___-__
 info: 
 info: Server lifted in `/Users/jh/Desktop/new/oauthy Kopie`
 info: To shut down Sails, press <CTRL> + C at any time.
 info: Read more at https://sailsjs.com/support.

debug: -------------------------------------------------------
debug: :: Tue May 29 2018 19:08:08 GMT+0200 (CEST)

debug: Environment : development
debug: Port        : 1337
debug: -------------------------------------------------------
TypeError: Cannot read property 'id' of undefined
    at /Users/jh/Desktop/new/oauthy Kopie/config/passport.js:17:17
    at pass (/Users/jh/Desktop/new/oauthy Kopie/node_modules/passport/lib/authenticator.js:294:9)
    at Authenticator.serializeUser (/Users/jh/Desktop/new/oauthy Kopie/node_modules/passport/lib/authenticator.js:299:5)
    at SessionManager.logIn (/Users/jh/Desktop/new/oauthy Kopie/node_modules/passport/lib/sessionmanager.js:14:8)
    at IncomingMessage.req.login.req.logIn (/Users/jh/Desktop/new/oauthy Kopie/node_modules/passport/lib/http/request.js:50:33)
    at /Users/jh/Desktop/new/oauthy Kopie/api/controllers/AuthController.js:94:9
    at Strategy.strategy.error (/Users/jh/Desktop/new/oauthy Kopie/node_modules/passport/lib/middleware/authenticate.js:353:18)
    at /Users/jh/Desktop/new/oauthy Kopie/node_modules/passport-oauth2/lib/strategy.js:197:27
    at /Users/jh/Desktop/new/oauthy Kopie/node_modules/passport-facebook/lib/strategy.js:181:5
    at passBackControl (/Users/jh/Desktop/new/oauthy Kopie/node_modules/oauth/lib/oauth2.js:134:9)
    at IncomingMessage.<anonymous> (/Users/jh/Desktop/new/oauthy Kopie/node_modules/oauth/lib/oauth2.js:157:7)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)


**Sails version1.0.1:
**Node versionv8.10.0:
**NPM version6.0.0:
**DB adapter namesails-mongo: N/A
DB adapter version: N/A
Operating system:

@sailsbot
Copy link

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

@streleck
Copy link

@SpaceG I'm not sure how to integrate passport, so I'd have to recommend using the built-in auth in Sails, as well as using await instead of callbacks. You can try it out by running sails new ______ and then choosing the "Web App" template. It won't have the Github and Twitter, etc. strategies built in, but you can start with working auth and then try integrating those features.

@SpaceG
Copy link
Author

SpaceG commented May 29, 2018

@streleck thats isnt with passportjs.. i think. man, i dont get fit here. sailsjs community is too small. no docus, no normali tutorials. everything looks like betas..

@sailsbot
Copy link

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

@SpaceG
Copy link
Author

SpaceG commented May 29, 2018

@streleck and the other point is, this shit sailsbot, man wtf?!.- come back everytimes.! - imao!- need a solution, by own, nothing bla bla, web app sailsjs. i want learning something here! or i will change it to vue.js or angularjs. - this suck. im here online in a world of 8 millard peoples and no one know a solution to fix this.? what a shame.! -

@SpaceG SpaceG closed this as completed May 29, 2018
@sailsbot
Copy link

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

@sailsbot
Copy link

Hi @SpaceG! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

@mikermcneil
Copy link
Member

@SpaceG not sure what happened there, but consolidated duplicate issues here, removed the "Needs cleanup" label to pacify sailsbot, and reopened

@raqem
Copy link
Contributor

raqem commented Apr 24, 2019

Hi @SpaceG I wanted to point you to a comment Mike made a while back about the use of social media auth. https://gitter.im/balderdashy/sails?at=5ad97aff1130fe3d36f7e390

If this is something you are still interested in pursuing this we would be able to help you further if you can make a repo from a fresh Sails app with minimal changes so we can pin-point what is causing the issue.

@raqem raqem added the repro please Could you reproduce this in a repository for us? label Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party package repro please Could you reproduce this in a repository for us?
Development

No branches or pull requests

5 participants