Created
December 8, 2019 07:02
-
-
Save alant/63ed179d87841dda502f5d2b7ff5d0b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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