admin管理员组

文章数量:1323715

I am creating a ReactJS and NodeJS application. While authenticating my user on route 'localhost:5000/user/signup' Internal server error with code 500 is received. For authenticating my user , I am using this auth.js file

import * as api from '../api'

export const signup=(authData,navigate)=>async(dispatch)=>{
    try {
        const response=await api.signUp(authData)
        let data=response.data;
        dispatch({type:"AUTH", data})
        navigate('/')
    } catch (error) {
        console.log(error)
    }
}

Here, on line 5 , authdata is where I think the error is. Maybe axios data format for response or something. The signUp function is as follows:

import axios from 'axios'

const API=axios.create({baseURL:'http://localhost:5000'})


export const signUp=(authData)=>API.post('/user/signup',authData,{headers:{"Content-Type" : "application/json"}})

And the function call is set from a form submit button, whose code snippet is as follows: The code snippet includes the format of data which I am passing.

let data=JSON.stringify({
                name:name,
                email:email,
                password:password
            });
            dispatch(signup(data),navigate)

The error is something like this, everytime I click on submit button:

AxiosError {message: 'Request failed with status code 500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …}
code
: 
"ERR_BAD_RESPONSE"
config
: 
{transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …}
message
: 
"Request failed with status code 500"
name
: 
"AxiosError"
request
: 
XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
response
: 
{data: {…}, status: 500, statusText: 'Internal Server Error', headers: {…}, config: {…}, …}
[[Prototype]]
: 
Error

I am creating a ReactJS and NodeJS application. While authenticating my user on route 'localhost:5000/user/signup' Internal server error with code 500 is received. For authenticating my user , I am using this auth.js file

import * as api from '../api'

export const signup=(authData,navigate)=>async(dispatch)=>{
    try {
        const response=await api.signUp(authData)
        let data=response.data;
        dispatch({type:"AUTH", data})
        navigate('/')
    } catch (error) {
        console.log(error)
    }
}

Here, on line 5 , authdata is where I think the error is. Maybe axios data format for response or something. The signUp function is as follows:

import axios from 'axios'

const API=axios.create({baseURL:'http://localhost:5000'})


export const signUp=(authData)=>API.post('/user/signup',authData,{headers:{"Content-Type" : "application/json"}})

And the function call is set from a form submit button, whose code snippet is as follows: The code snippet includes the format of data which I am passing.

let data=JSON.stringify({
                name:name,
                email:email,
                password:password
            });
            dispatch(signup(data),navigate)

The error is something like this, everytime I click on submit button:

AxiosError {message: 'Request failed with status code 500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …}
code
: 
"ERR_BAD_RESPONSE"
config
: 
{transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …}
message
: 
"Request failed with status code 500"
name
: 
"AxiosError"
request
: 
XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
response
: 
{data: {…}, status: 500, statusText: 'Internal Server Error', headers: {…}, config: {…}, …}
[[Prototype]]
: 
Error

Share Improve this question edited Oct 3, 2022 at 11:01 VLAZ 29.1k9 gold badges63 silver badges84 bronze badges asked Oct 3, 2022 at 10:53 Devansh ShahDevansh Shah 431 gold badge1 silver badge3 bronze badges 1