Sign-in

The API endpoint to sign in a user is declared in the following route.

mern-skeleton/server/routes/auth.routes.js:

router.route('/auth/signin').post(authCtrl.signin)

When the Express app gets a POST request at '/auth/signin', it executes the signin controller function.

mern-skeleton/server/controllers/auth.controller.js:

const signin = (req, res) => {  User.findOne({    "email": req.body.email  }, (err, user) => {    if (err || !user)      return res.status('401').json({        error: "User not found"      })    if (!user.authenticate(req.body.password)) {      return res.status('401').send({        error: "Email and password don't match."      })    }    const token = jwt.sign({      _id: user._id    }, config.jwtSecret)    res.cookie("t", token, {      expire: new Date() + 9999    }) return res.json({ ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.