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

223
Visualizações
Getting `[Object: null prototype]` with Fastify, expected values are undefined

I register the following plugins on server boot:

const registerPlugins = (app) => {
    app.register(require('fastify-cors'), {
        origin: '*',
        methods: ['POST', 'PUT', 'DELETE'],
        credentials: true,
    });

    app.register(require('fastify-static'), {
        root: path.join(__dirname, 'client', 'build'),
    });

    app.register(require('fastify-helmet'), { contentSecurityPolicy: false });
    app.register(require('fastify-multer').contentParser);
    app.register(require('fastify-formbody'));
    app.register(require('fastify-qs'), {});
};

And I have a simple route that looks like this:

fastify.post('/login', {
    handler,
})

And my handler looks like this:

const handler = async (req, reply) => {
    try {
        const { email, password } = req.body;

        console.log('req.body', req.body);
        console.log('email', email);
        console.log('password', password);

        return reply.send();
    } catch (err) {
        return reply.code(500).send({ error: err });
    }
};

email and password are undefined for some reason, but when I print req.body, it gives me this:

req.body [Object: null prototype] {
   '{"email":"asdasd","password":"asdas"}': ''
}

What am I doing wrong here?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Hello Juan, I had the same problem.

I didn't find a clean way get rid of it. To avoid [Object: null prototype] I parsed again the body.

JSON.parse(JSON.stringify(req.body)) // => {"email":"asdasd","password":"asdas"}
about 4 years ago · Antoine Pertoldi 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