Created
May 11, 2021 18:03
-
-
Save ManishPoduval/b3b12eca9fdc9f742bb49ffb4b0ba39b to your computer and use it in GitHub Desktop.
This file contains 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 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