Click here to Skip to main content
15,943,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
import React from "react";
import { Button, Form, Input } from "antd";
import { Link } from "react-router-dom";
import axios from "axios";
import toast from "react-hot-toast";
function Register() {
  const onFinish = async (values) => { 
    try {
      const response = await"/api/user/register", values);
      if ( {
      } else {
    } catch (error) {
      toast.error("something went wrong");
  return (
    <div className="authentication">
      {" "}
      <div className="authentication-form card p-2">
        {" "}
        <h1 className="card-title">Nice to meet You</h1>
        <Form layout="vertical" onFinish={onFinish}>
          <Form.Item label="Name" name="name">
            <Input placeholder="Name" />
          <Form.Item label="Email" name="email">
            <Input placeholder="Email" />
          <Form.Item label="Password" name="password">
            <Input placeholder="Password" type="password" />
          <Button className="primary-button my-3" htmlType="submit">
          <Link to="/login" className="anchor mt-2">
            Click here to continue

export default Register;

const express = require("express");
const app = express();
const dbconfig = require("./config/dbconfig");
const userRoute = require("./routes/userRoute");
app.use("/api/user", userRoute);
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`node nerver started at port ${port}`));

const express = require("express");
const router = express.Router();
const User = require("../models/userModel");
const bcrypt = require("bcryptjs");"/register", async (req, res) => {
  try {
    const userExists = await User.findOne({ email: });
    if (userExists) {
      return res
        .send({ message: "user exists alreayd", success: false });
    const password = req.body.password;
    const salt = await bcrypt.genSalt(10);
    const hashedpassword = await bcrypt.hash(password, salt);

    req.body.password = hashedpassword;
    const newuser = new User(req.body);
    res.status(200).send({ message: "user created", success: true });
  } catch (error) {
    return res.status(500).send({ message: "Error", success: false, error });
});"/login", async (req, res) => {
  try {
  } catch (error) {}

module.exports = router;

const mongoose = require("mongoose");
const userSchema = new mongoose.Schema(
    name: { type: String, required: true },
    email: { type: String, required: true },
    password: { type: String, required: true },
  { timestamps: true }
const userModel = mongoose.model("users", userSchema);
module.exports = userModel ;

What I have tried:

The Server Is Up And Running.
I tried both, only the get request works, is there any reason why post request doesn't work from the front end side or does is it something to do with the API that im sending my request to
Pete O'Hanlon 21-Feb-23 11:42am    
Have you looked at the error information? Print this out in the catch block so you know what is causing the error.
tan25 22-Feb-23 3:48am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900