Twitter authentication with Passport middleware in Node Twitter authentication with Passport middleware in Node express express

Twitter authentication with Passport middleware in Node


You have to define your User type somewhere. It looks like you expect this thing User to exist and to have the functions findOrCreate and findById, but you never defined that anywhere. Where are you 'finding' these users? The ones that aren't found, where are they being 'created'? Are you using a database? How do you connect to the database? I think you forgot the "Model" step. You might want to take a look at Mongoose Auth which is like Passport but it plugs directly into Mongoose, which connnects to a Mongo Database


This is what I did when I faced the same error which says User isn't defined:

passport.use(new TwitterStrategy({    consumerKey: keys.twitterConsumerKey,    consumerSecret: keys.twitterConsumerSecret,    callbackURL: "http://local.host:3000/auth/twitter/callback"  },  function(token, tokenSecret, profile, done) {    done(null, profile);  }));


I ran into the same issue when integrating the BeatsMusic OAuth2 strategy for Passport within Kraken. It looks like the examples for the various Kraken Passport integration strategies use the same simple example documentation which did not explicitly discuss the User object (understandable).

I figured out (from digging thru the passport strategy examples found @ https://github.com/krakenjs/kraken-examples/tree/master/with.passport) that the User is intended to be a model based on the Mongoose model schema and also is configured with the https://github.com/drudge/mongoose-findorcreate plugin.

After i included the User = require('../PATH_TO/user') and added this plugin to the User model, voila! no more errors :)

Sounds like you don't need the DB functionality so you are probably good with removing the auth check.

Hope this helps for anyone else having similar issues.