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.
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) {
return done(null, profile);
}
)
);
Try this