Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
My database gets an object returned instead of a value

I am doing a post request on my database for user registers & every time the email gets returned as an object with this {"email":"karl@gmail.com"} instead of this karl@gmail.com

This is the nodejs

app.post("/register", (req, res) => {
  const { email, name, password } = req.body;
  var salt = bcrypt.genSaltSync(10);
  var hash = bcrypt.hashSync(password, salt);
  knex
    .transaction((trx) => {
      trx
        .insert({
          hash: hash,
          email: email,
        })
        .into("login")
        .returning("email")
        .then((loginEmail) => {
          return trx("users")
            .returning("*")
            .insert({
              email: loginEmail[0],
              name: name,
              joined: new Date(),
            })
            .then((user) => {
              res.json(user[0]);
            });
        })
        .then(trx.commit)
        .catch(trx.rollback);
    })
    .catch((err) => res.status(400).json("E-mail is already in use"));
});

This is how it looks in my 1st database

 14 | Karl      | {"email":"karl@gmail.com"}         |       0 | 2022-01-18 04:02:03.643

This is how it looks in my 2nd database

 12 | $2a$10$WsbEExtpu14ps7aK6AYbxOknedUaLusApL8MlD8lv0lCtknBIuPE. | karl@gmail.com
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

you are receiving a JSON object decode that and you will get your email out. also don't understand why you store {"email": "karl@gmail.com"} when your column should be labeled email and store the value karl@gmail.com. Best of luck!

about 4 years ago · Juan Pablo Isaza Relatório

0

loginEmail is an array of results, and each row is an object. You need to get the email property from that object.

            .insert({
              email: loginEmail[0].email,
              name: name,
              joined: new Date(),
            })
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda