Why is the POST not working on my Mongodb?

Asked

Viewed 62 times

1

Whenever I execute the post command the Inuit returns me an empty User.

router.post('/register', async (req,res) => {
    const { email } = req.body;

    try {
        if (await User.findOne({ email }))
            return res.status(400).send({ error: 'Usuário Existente'});

        const user = await User.create(req.body);
        user.senha = undefined;

        return res.send({
            user,
            token: geradortoken({ id:user.id }), 
        });
    } catch (err) {
        return res.status(400).send({error: 'Falha no registro'});
    }
});

1 answer

0

To return past information to the user’s creation, try to put in place:

return res.send();

Place:

return res.json(user);

Thus a JSON will be returned with user information through Insomnia.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.