I am trying to make an API call with bearer token to get the data. But there an error Access to fetch at 'https://MYAPI..' from origin 'http://localhost:3000' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. Also, my token is null. I try to get from localStorage.local storage token example Here is my token. Can anyone suggest to me where is my problem? Thanks
const [user, setUsers] = React.useState([]);
var token = localStorage.getItem("accessToken");
React.useEffect(()=>{
fetch(URLS.GetAllUsers,{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
}})
.then(res=> res.json())
.then((response) => {
setUsers(response.displayName)
})
.catch((error) => console.log(error));
});