Skip to content

Instantly share code, notes, and snippets.

@alant
Created December 8, 2019 07:02
Show Gist options
  • Save alant/63ed179d87841dda502f5d2b7ff5d0b4 to your computer and use it in GitHub Desktop.
Save alant/63ed179d87841dda502f5d2b7ff5d0b4 to your computer and use it in GitHub Desktop.
const loginWithFacebook = async (req, res, next) => {
try {
const user_resp = await axios.get(`https://graph.facebook.com/${GRAPH_API_VERSION}/me`, {
params: {
fields: "id, name, email, picture",
access_token: req.body.access_token
}
});
req.email = user_resp.data.email
let profile = {
email: user_resp.data.email,
id: user_resp.data.id,
name: user_resp.data.name,
avatar_url: user_resp.data.picture.data.url
};
await User.upsertFacebookUser(profile);
} catch (err) {
console.log("====> facebook err: ", err);
res.status(500).send({ auth: false, message: 'Failed to auth through facebook.' });
}
next();
}
app.post('/login/facebook', loginWithFacebook, issueJwt, (req, res) => {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment