Cuando quiero eliminar un dato desde la aplicación a una base de datos en Firebase:
Access to fetch at 'https://fir-movie-app-2761f-default-rtdb.firebaseio.com/movies.json/-Mlv85nQwY-xehVg_Tn2' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Movie.js:8 DELETE https://fir-movie-app-2761f-default-rtdb.firebaseio.com/movies.json/-Mlv85nQwY-xehVg_Tn2 net::ERR_FAILED
Mi código es :
import React from 'react';
import classes from './Movie.module.css';
const Movie = props => {
const deleteHandler = async () => {
try {
const response = await fetch(
`https://fir-movie-app-2761f-default-rtdb.firebaseio.com/movies.json/${props.id}`,
{
method: 'DELETE',
headers: {
'Content-type': 'application/json',
},
}
);
if (!response.ok) {
throw new Error('Something went wrong ' + response.status);
}
const data = await response.json();
console.log(data);
} catch (error) {
alert(error);
}
};
return (
<li className={classes.movie}>
<h2>{props.title}</h2>
<h3>{props.releaseDate}</h3>
<p>{props.openingText}</p>
<button onClick={deleteHandler}>X</button>
</li>
);
};
export default Movie;