drudge / passport-facebook-token

Passport strategy for authenticating with Facebook access tokens using the OAuth 2.0 API.
MIT License
390 stars 80 forks source link

User is not defined at ```User.findOrCreate({ facebookId: profile.id }``` in strategy config? #90

Closed sebastiangug closed 5 years ago

sebastiangug commented 5 years ago

What am I missing here? I've been through all the threads here and googled it for a while:

But when all is good and I send a request with that good token either from Postman or from my frontend I get Internal Server Error telling me User is not defined at that line. What am I missing?

Route code:

app.get(
  '/user',
  passport.authenticate('facebook-token', { session: false }),
  function(req, res) {
    res.send('SUCCESS');
  }
);

All other code without imports:

app.use(cors());
app.use(express.json());
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(passport.initialize());
passport.use(
  new FacebookTokenStrategy(
    {
      clientID: config.get('facebook.clientID'),
      clientSecret: config.get('facebook.clientSecret')
    },
    function(accessToken, refreshToken, profile, done) {
      User.findOrCreate({ facebookId: profile.id }, function(error, user) {
        return done(error, user);
      });
    }
  )
);

and I'm importing the npm package exactly as in the docs:

const FacebookTokenStrategy = require('passport-facebook-token');

I'm all out of ideas on this one.