Answer the question
In order to leave comments, you need to log in
Is it possible to use req.query in a POST request?
Hello, I'm checking the referral link with req.query.ref, but it doesn't seem to work on POST request, or I'm doing something wrong.
This is what the address looks like in the address bar: localhost:3000/signup?ref=5fa277b302227a1c04ea9612 ,
where after ?ref= comes the _id of the user from the database.
This is how I do it in GET:
router.get('/signup', async (req, res) => {
const человек = await User.findOne({ _id: req.query.ref })
console.log(человек)
})
console.log(req.query)
in GET shows { ref: '5fa277b302227a1c04ea9612' }
, {}
Answer the question
In order to leave comments, you need to log in
The error was in the HTML form, I had to remove /signup in the action
Now everything seems to be working. PS Thanks to Michael from the comments
<form class="signup-form" action="" method="POST">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question