0

Error Message

AxiosError {message: 'Request failed with status code 500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …}
code
: 
"ERR_BAD_RESPONSE"
config
: 
{transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}
message
: 
"Request failed with status code 500"
name
: 
"AxiosError"
request
: 
XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
response
: 
{data: 'Something went worng...', status: 500, statusText: 'Internal Server Error', headers: AxiosHeaders, config: {…}, …}
stack
: 
"AxiosError: Request failed with status code 500\n    at settle (http://localhost:3000/main.ccb3dfb81e3968e0b0de.hot-update.js:1616:12)\n    at XMLHttpRequest.onloadend (http://localhost:3000/main.ccb3dfb81e3968e0b0de.hot-update.js:327:66)"
[[Prototype]]
: 
Error

Fronend API file

import axios from 'axios'

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

export const logIn = (authData) => API.post('/user/login', authData);
export const signUp = (authData) => API.post('/user/signup', authData);

Frontend Auth file

import { Navigate } from 'react-router-dom'
import * as api from '../api'

export const signUp = (authData, history) => async (dispatch) => {
    try {
        const { data } = await api.signUp(authData)
        dispatch({ type: 'AUTH', data})
        Navigate('/')
     } catch (error) {
           console.log(error)
     }
}

export const login = (authData, history) => async (dispatch) => {
    try {
        const { data } = await api.signUp(authData)
        dispatch({ type: 'AUTH', data})
        Navigate('/')
     } catch (error) {
        console.log(error)
     }
}

Backend Index

import express from 'express'
import mongoose from 'mongoose'
import cors from 'cors'

import userRoutes from './routes/users.js'

const app = express();
app.use(express.json({limit: "30mb", extended: true}))
app.use(express.urlencoded({limit:"30mb", extended: true}))
app.use(cors());

app.get('/',(req, res) => {
     res.send("This is Ask Panda API")
})

app.use('/user', userRoutes)

const PORT = process.env.PORT || 5000

const CONNECTION_URL = "<mongodb link>"

mongoose.connect ( CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true})
   .then(() => app.listen(PORT, () => {console.log('server running on port ${PORT}')} ))
   .catch((err) => console.log(err.message))

Am trying to build simple sing up authentication in MERN, just learning it, I am following Instructions from a Tutorial but yet I get this error, in the Tutorial, when typing Email and Password, it console logs the data in database and shows the result, but am just getting the above error, I feel like I typed something wrong.

  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Dec 31 '22 at 05:47

0 Answers0