Access to XMLHttpRequest at 'http://hmdm-server:8080/rest/public/jwt/login' from origin 'http://localhost:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
i am getting the above error for this given react code
import React from 'react'
import { useState } from 'react'
import md5 from 'md5';
import axios from 'axios';
const Login = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const handlelogin = async (e) => {
e.preventDefault();
console.log(username, password);
const hashedpassword = md5(password).toUpperCase();
try {
const res = await axios.post('http://hmdm-server:8080/rest/public/jwt/login', {
login: username,
password: hashedpassword
});
const token = res.data.token;
console.log(token);
localStorage.setItem('token', token);
alert('Login successful');
} catch (error) {
console.error(error);
}
}
return (
<>
<div>Login</div>
<form onSubmit={handlelogin}>
<input type="text" placeholder='username' onChange={(e) => setUsername(e.target.value)} />
<input type="password" placeholder='password' onChange={(e) => setPassword(e.target.value)} />
<button type='submit'>Login</button>
</form>
</>
)
}
export default Login;