Reputation: 1115
I am trying to use passport-facebook for logging in with my app. I am having some trouble redirecting when the user actually logs in. Basically the issue is that after going to /auth/facebook and redirecting to facebook login (and entering credentials, then hitting login button) the page will load forever, and not redirect. What am I doing wrong?
Here is my app.js:
import express from 'express';
import bodyParser from 'body-parser';
import session from 'express-session';
import passport from 'passport';
import FacebookStrategy from 'passport-facebook';
const app = express();
var fbOpts = {
clientID: ****,
clientSecret: ****,
callbackURL: '/auth/facebook/callback',
profileFields: ['id', 'displayName', 'photos', 'email']
}
var fbCallback = (accessToken, refreshToken, profile, cb) => {
console.log(accessToken, refreshToken, profile, cb);
//save to database
}
app.use(bodyParser.json());
app.use(session({
secret:'foobar',
resave:true,
saveUnitialized:true
}))
passport.use(new FacebookStrategy(fbOpts,fbCallback))
app.get("/",(req,res)=>{
res.send("<a href='/auth/facebook'>Login with Facebook</a>")
});
app.get("/auth/facebook",passport.authenticate('facebook'));
app.get('/auth/facebook/callback',
passport.authenticate('facebook', {
successRedirect : '/profile',
failureRedirect : '/'
})
);
app.get("/profile",(req,res)=>res.send("profile page"))
app.listen(3000);
Can anyone tell me what I am missing or doing wrong with redirecting back to my website ?
Also, I can tell the login is properly working because if I look in my terminal's console I can see my user information for facebook, such as profile picture, name, id, etc.
Upvotes: 0
Views: 587
Reputation: 395
you've probably fixed this by now. But just for anybody else out there trying to get around this. There are many reference points that you ought to look out for. I tried to change the redirect stuff on https://developers.facebook.com/apps for ages but nothing was working. Kept getting the message URL Blocked. Whitelist etc etc.
The problem was actually solved because in my ids file where i stored my id's I had set the callbackURL: 'http://127.0.0.1:3000/auth/facebook/callback' instead of callbackURL: localhost:3000.
Silly mistake, but just thought i would share to let you know to keep checking all the possible reference points.
Upvotes: 1