text: const {User} = require('../models')
  const jwt = require('jsonwebtoken')
  const config = require('../config/config')
  
  function jwtSignUser (user) {
    const ONE_WEEK = 60 * 60 * 24 * 7
    return jwt.sign(user, config.authentication.jwtSecret, {
      expiresIn: ONE_WEEK
    })
  }
  
  module.exports = {
    async signup (req, res) {
      try {
        const user = await User.create(req.body)
        const userJson = user.toJSON()
        res.send({
          user: userJson,
          token: jwtSignUser(userJson)
        })
      } catch (err) {
        res.status(400).send({
          error: 'Email account is already in use.'
        })
      }
      // res.send({
      //   message: `Hello ${req.body.email}! Your user was signed up! Have fun!`
      // })
    },
    async signin (req, res) {
      try {
        const {email, password} = req.body
        const user = await User.findOne({
          where: {
            email: email
          }
        })
        console.log('have user')
        if (!user) {
          return res.status(403).send({
            error: 'The Sign In information was incorrect'
          })
        }
        const isValidPassword = await user.comparePassword(password)
        if (!isValidPassword) {
          return res.status(403).send({
            error: 'The Sign In information was incorrect'
          })
        }
        const userJson = user.toJSON()
        console.log(userJson)
        res.send({
          user: userJson,
          token: jwtSignUser(userJson)
        })
      } catch (err) {
        res.status(500).send({
          error: 'An error has ocurred trying to Sign In'
        })
      }
    }
  }
  