const axios = require('../axios')

const atinaApi = process.env.ATINA_FE_API || '167.172.170.78';

module.exports = async (req, res) => {
    // Assuming the username and password are provided in the request body
  const { user, password, entidad } = req.body;

  return axios({
    method: 'post',
    headers: {
      "Content-Type": "application/json",
      entidad: entidad,
    },
    url: `https://${atinaApi}:8082/api/login`,
    data: {
      user, 
      password
    }
    
  }).then(response => {
    // Return the response from the login endpoint
    res.json({...response.data, jwttoken: response.headers['jwttoken']});
  })
  .catch(error => {
    console.error(JSON.stringify(error.response.data));
    // Return any error that occurred during the request
    res.status(error.response.status).json({ ...error.response.data });
  });

}