text: // Dependencies
  const router = require('express').Router();
  const { User } = require('../../models');
  
  // When user signs in, credentials are saved into the db
  router.post('/', async (req, res) => {
      try {
          const userData = await User.create(req.body);
  
          req.session.save(() => {
              req.session.user_id = userData.id;
              req.session.logged_in = true;
  
              res.status(200).json(userData);
          })
      }
  
      catch (err) {
          console.log(err);
          res.status(404).json(err);
      }
  })
  
  // When user logs in, credentials are saved and allows user to access page
  // only if credentials are correct!
  router.post('/login', async (req, res) => {
      try {
          const userData = await User.findOne({ where: { email: req.body.email } });
  
          if (!userData) {
              res
                  .status(400)
                  .json({ message: 'Incorrect email or password, please try again' });
              return;
          }
  
          const validPassword = await userData.checkPassword(req.body.password);
  
          if (!validPassword) {
              res
                  .status(400)
                  .json({ message: 'Incorrect email or password, please try again' });
              return;
          }
  
          req.session.save(() => {
              req.session.user_id = userData.id;
              req.session.logged_in = true;
  
              res.json({ user: userData, message: 'You are now logged in!' });
          });
      }
  
      catch (err) {
          res.status(404).json(err);
      }
  })
  
  // Signup
  router.post('/signup', async (req, res) => {
      try {
        const userData = await User.create(req.body);
        req.session.save(() => {
          req.session.user_id = userData.id;
          req.session.logged_in = true;
          res.status(200).json(userData);
        });
      } catch (err) {
        res.status(400).json(err);
      }
    });
  
  // When user logs out, their session is ended if they were logged in
  router.post('/logout', async (req, res) => {
      if (req.session.logged_in) {
          req.session.destroy(() => {
              res.status(204).end();
          });
      } 
      
      else {
          res.status(404).end();
      }
  })
  
  // Export this router
  module.exports = router;