import bcrypt from 'bcrypt';
import jwt from 'jsonwebtoken';
import dotenv from 'dotenv';
import model from '../models';

dotenv.config();
const User = model.User;

module.exports = {
  create(req, res) {
    const username = req.body.username;
    const email = req.body.email;
    const salt = bcrypt.genSaltSync(10);
    const hash = bcrypt.hashSync(req.body.password, salt);

    User.sync({ force: false }).then(() => {
      User
        .create({
          username,
          password: hash,
          email,
          salt
        })
        .then((newUser) => {
          const token = jwt.sign({
            username: newUser.username,
            email: newUser.email
          },
          process.env.JWT_SECRET,
          {
            expiresIn: '2 days'
          });
          res.status(201).json({
            user: newUser,
            tok: token
          });
        })
        .catch((error) => {
          res.status(400).json({
            loginError: `${error.errors[0].message}`
          });
        });
    });
  }
};


@@ -780,32 +780,39 @@
   %7D);%0A          
+return 
 res.status(201).
@@ -835,24 +835,44 @@
    user:
+ %7B%0A              id:
  newUser
 ,%0A      
@@ -863,16 +863,19 @@
  newUser
+.id
 ,%0A      
@@ -884,12 +884,187 @@
     
-tok:
+  username: newUser.username,%0A              email: newUser.email,%0A              updatedAt: newUser.updatedAt,%0A              createdAt: newUser.createdAt%0A            %7D,%0A           
  tok
@@ -1168,23 +1168,15 @@
     
-login
 Error: 
-%60$%7B
 erro
@@ -1198,10 +1198,8 @@
 sage
-%7D%60
 %0A   

Edit response object