Hello I am trying to create login form to connect to mongodb. Everything is correctly install but I keep getting the error
AxiosError code: "ERR_BAD_REQUEST"
import { useState } from "react"
import axios from 'axios'
export default function Login(){
const [email ,setEmail] = useState('')
const [password, setPassword] = useState('')
const handleSubmit = (e) =>{
e.preventDefault()
axios.post('http://localhost:5173/login' ,{email ,password})
.then(result => console.log(result))
.catch(err => console.log(err))
}
console.log(email)
console.log(password)
return (
<div>
<form onSubmit={handleSubmit}>
<div>
<label htmlFor="email">email</label>
<input type="email" name="email" onChange={(e)=> setEmail(e.target.value)}/>
</div>
<div>
<label htmlFor="email">password</label>
<input type="password" name="password" onChange={(e)=> setPassword(e.target.value)}/>
</div>
<button type="submit">log in </button>
</form>
</div>
)
}
I ahve already checked the port and endpoind, and they are correct and that is link to code server https://www.useblackbox.io/editor?id=7849c828-bd17-4885-b17f-07a3f6d3bad1
2
Answers
AxiosError {message: 'Request failed with status code 404', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …} code: "ERR_BAD_REQUEST" config: {transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …} message: "Request failed with status code 404" name: "AxiosError" request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …} response: {data: '', status: 404, statusText: 'Not Found', headers: AxiosHeaders, config: {…}, …} stack: "AxiosError: Request failed with status code 404n at settle (http://localhost:5173/node_modules/.vite/deps/axios.js?v=55c2aff0:1206:12)n at XMLHttpRequest.onloadend (http://localhost:5173/node_modules/.vite/deps/axios.js?v=55c2aff0:1423:7)" [[Prototype]]:
Are you certain this endpoint is correct? Status code 404 means not found