Skip to content

Instantly share code, notes, and snippets.

@ManishPoduval
Created May 11, 2021 18:03
Show Gist options
  • Save ManishPoduval/b3b12eca9fdc9f742bb49ffb4b0ba39b to your computer and use it in GitHub Desktop.
Save ManishPoduval/b3b12eca9fdc9f742bb49ffb4b0ba39b to your computer and use it in GitHub Desktop.
const router = require("express").Router();
const UserModel = require('../models/User.model')
// The client makes a API request to this url sending the data in the body
router.post("/facebook/info", (req, res, next) => {
const {name, email, image, facebookId} = req.body
// the name itself will include the last name
try {
// Create the user in the DB
UserModel.create({firstName: name, facebookId, image, email})
.then((response) => {
// Save the loggedInInfo in the session
// We'll stick to using sessions just to not over complicate the students with tokens and cookies
req.session.loggedInUser = response
res.status(200).json({data: response})
})
}
catch(error) {
res.status(500).json({error: `${error}`})
}
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment