Hi guys!
I’ve been stuck on this for a long time and have tried everything.
I’m starting the Voting App project and I’m using passport-facebook for authentication. Logging in and out works great in development but after deploying it Heroku, it stops working. The URL goes to /auth/facebook but it doesn’t not get redirected. I’m not sure what I did wrong… please help! There is also no error in the console so I’m not sure where to look for mistakes. I’ve also added the heroku domain to facebook redirect urls so that shouldn’t be the problem.
My passport.js
passport.serializeUser((user, done) => {
done(null, user.id);
});
passport.deserializeUser((id, done) => {
User.findById(id).then(user => done(null, user));
});
passport.use(
new FacebookStrategy(
{
clientID: keys.facebookClientID,
clientSecret: keys.facebookClientSecret,
callbackURL: '/auth/facebook/callback',
profileFields: ['id', 'name'],
proxy: true
},
(accessToken, refreshToken, profile, done) => {
User.findOne({ facebookId: profile.id }).then(user => {
if (user) {
return done(null, user);
} else {
new User({ facebookId: profile.id })
.save()
.then(user => done(null, user));
}
});
}
)
);
My authRoutes.js
app.get('/auth/facebook', passport.authenticate('facebook'));
app.get(
'/auth/facebook/callback',
passport.authenticate('facebook'),
(req, res) => {
res.redirect('/');
}
);
Here is my Github repo and the Heroku app so you can see what I mean.
Thanks in advance!