Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
nodejs mongoDB connection login page

When I send username, password, email by postman it works and adds infos to mongodb schema but in login page at react it doesn't work. I would really appreciate if someone could help. Thank you so much.

console

React logic:

const [username, setUserName] = useState("");
const [password, setPassword] = useState("");
const [email, setEmail] = useState("");
    
const handleSubmit = async (e) =>{
  console.log(".....");
     e.preventDefault();
    const res =  await axios.post("/auth/register", {
     username,
     email,
     password,
    });
    console.log(res)
    };

Node.js logic:

router.post("/register", async (req, res) => {
  
  console.log("here")
      try{   
          const salt = await bcrypt.genSalt(10);
          const hashedPassword = await bcrypt.hash(req.body.password, salt);

          const newUser = new User({
            username: req.body.username,
            email: req.body.email,
            password: hashedPassword,
            });

      const user = await newUser.save(); 
      res.status(200).json(user);
      } catch(err) {
        console.log(err);
      }
        
    }
);


/////////////////////

app.use("/api/auth", authRoute);


app.use("/",(req,res)=>{
    console.log("main url")
})

app.listen("3000",()=>{
    console.log("backend running");
})
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

make sure that you send the request to the right route/server, maybe you miss-typed the port or the route itself.

about 4 years ago · Juan Pablo Isaza Report

0

I believe this line const res = await axios.post("/auth/register", { isn't matching your backend app.use("/api/auth", authRoute);

about 4 years ago · Juan Pablo Isaza Report

0

Looks like you defined your register logic on /register endpoint, BUT you are sending request to /auth/register endpoint.

Try to change your React logic to send request to /register endpoint:

const res =  await axios.post("/register", {
  username,
  email,
  password,
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!