A short snippet to assist in linking of social media accounts in a userschema when using mongoDB & mongoose.js async function generateOrFindUser(accessToken, refreshToken, profile, done) { const email = profile.emails[0].value; const name = profile.displayName || profile.username; const facebookId = profile.id; if (email) { let updatedUser = await User.findOneAndUpdate({facebookId},{email,name,facebookId}, {‘upsert’: true, ‘new’: true}, done); } else { var emailError = new Error(“Your email privacy settings prevent
[ Read More ]