stefanbuck / sails-social-auth-example

Sails.js Social Auth example with Passport and MongoDB
243 stars 62 forks source link

Instructions for adding new Strategies #29

Closed angelxmoreno closed 9 years ago

angelxmoreno commented 9 years ago

Could someone please provide instructions for adding new strategies?

  1. I installed passport-instagram via npm
  2. in my config/express.js
  3. I added InstagramStrategy = require('passport-instagram').Strategy
  4. I added a new entry for the InstagramStrategy like so
passport.use(new InstagramStrategy({
      clientID: '---',
      clientSecret: '---',
      callbackURL: "http://localhost:1337/auth/instagram/callback"
    }, verifyHandler));
  1. In my AuthController.js i added an entry for Instagram
instagram: function(req, res) {
    passport.authenticate('instagram', { failureRedirect: '/login' }, function(err, user) {
      req.logIn(user, function(err) {
        console.log(err)
        if (err) {
          console.log(err);
          res.view('500');
          return;
        }

        res.redirect('/');
        return;
      });
    })(req, res);
  },

However when i try to go to /auth/instagram and I am redirected back to my app as i should but i get an error on the node saide saying: [TypeError: Cannot read property 'uid' of undefined]. What am I missing?

stefanbuck commented 9 years ago

Sorry for the delay. Did you solved the issue in the meantime? If not, start debugging here https://github.com/stefanbuck/sails-social-auth-example/blob/master/config/express.js#L11. At this point you have access to the response from the Instagram API with all the provided information. Please verify that everything is stored in the database. The error occurs, because the serializeUser method get tries to get a uid from user which is in your case undefined. https://github.com/stefanbuck/sails-social-auth-example/blob/master/config/express.js#L41

i hope this helps you further