Hi there! Hoping to get some help as I found zero information on how to fix this issue.
In my application, after the user signs up through passport-facebook I allow him to change his username. However, if he does so, then after logging out he is never let back in through facebook login.
I'm not changing facebookId, just the username, but somehow that breaks the login flow..
Here is my facebook strategy
`passport.use(new FacebookStrategy({
clientID: process.env['FACEBOOK_APPID' + env],
clientSecret: process.env['FACEBOOK_APPSECRET' + env],
callbackURL: process.env[ 'WEBSITE_' + env] + "auth/facebook/callback",
profileFields: ['id', 'emails']
},
function(accessToken, refreshToken, profile, done) {
User.findOne({ username : profile.id}, function(err, user) {
if (err) { return done(err); }
if (!user){
const newUser = new User({
username: profile.emails[0].value.split('@')[0],
facebookId: profile.id,
email: profile.emails[0].value,
numberOfLogs: 0
});
newUser.save(function(err) {
if(err) {
console.log(err);
} else {
done(null, newUser);
}
});
}else{
//if a user already exists too
done(null, user);
}
});
}
And that's a sample user in the database after changing the username:
{ "_id": { "$oid": "5ba2ae50e484f5000494b62e" }, "username": "hi_hello", "facebookId": "101191784185559", "email": "daria.tsenter@gmail.com", "numberOfLogs": 0, "__v": 0 }
Hi there! Hoping to get some help as I found zero information on how to fix this issue.
In my application, after the user signs up through passport-facebook I allow him to change his username. However, if he does so, then after logging out he is never let back in through facebook login.
I'm not changing facebookId, just the username, but somehow that breaks the login flow..
Here is my facebook strategy `passport.use(new FacebookStrategy({ clientID: process.env['FACEBOOK_APPID' + env], clientSecret: process.env['FACEBOOK_APPSECRET' + env], callbackURL: process.env[ 'WEBSITE_' + env] + "auth/facebook/callback", profileFields: ['id', 'emails'] }, function(accessToken, refreshToken, profile, done) { User.findOne({ username : profile.id}, function(err, user) { if (err) { return done(err); } if (!user){ const newUser = new User({ username: profile.emails[0].value.split('@')[0], facebookId: profile.id, email: profile.emails[0].value, numberOfLogs: 0 });
));`
My authentication
app.get('/auth/facebook', passport.authenticate('facebook', { scope : ['email'], failureRedirect: '/', successRedirect: '/addlog'}));
And that's a sample user in the database after changing the username:
{ "_id": { "$oid": "5ba2ae50e484f5000494b62e" }, "username": "hi_hello", "facebookId": "101191784185559", "email": "daria.tsenter@gmail.com", "numberOfLogs": 0, "__v": 0 }
Thank you very much!