React: Auth.js:30 POST http://localhost:5000/api/users/signup 500 (Internal Server Error)

internal server error when I’m using fetch api
I checked the api using postman its working fine

code

 const authSubmitHandler = async event=>{
            event.preventDefault();
            // AuthContext.login();
            const data = new FormData(event.target);
            // console.log(data.get('email'));
            // console.log(data.get('name'));
            // console.log(data.get('password'));
            if(this.state.isLogin){}
            else{
            try{
               const response = await fetch('http://localhost:5000/api/users/signup',
                {
                    method:'POST',
                    headers:{
                        'Content-Type':'application/json'
                    },
                    body:JSON.stringify(data)
                });
                    const responseData = response.json();
                    console.log(responseData);
            }
            catch(err){
                console.log(err);
            } 
        }
    }

A 500 error usually means that there is a problem with your server. You are logging out the error - what does it say? Can you create a simple ping endpoint and hit that from your code?

the error was due to not using await here

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.