Quick question on last feature in Weather App
I am using an API with the Headers: "x-api-key" way of varifying the key in order to make sure the user can't put in any names that are not cities.
The following is my code. Something must be off that I am not aware of because the api wont call. It makes the same 400 error as when i didn't have the key at all:
const handleSubmit = async (event) => {
event.preventDefault();
if (value) {
try {
setIsLoading(true);
const { data } = await axios(
{
headers: {
Authorization: {
"x-api-key": "pR/pMV9hptKNyk1e2i5DjQ==s5ppiwzYglSKzYj0",
},
},
}
);
if (value.toLowerCase() === data.name.toLowerCase()) {
const updatedCities = [
...cities,
{ city: value, id: Math.random() - Math.random() },
];
setCities(updatedCities);
setValue("");
setIsLoading(false);
}
} catch (err) {
setError(err.message);
setIsLoading(false);
setTimeout(() => {
setError("");
}, 5000);
}
}
};
3
2 comments
Samuel Haraway
5
Quick question on last feature in Weather App
Developer Pro
skool.com/developerpro
Learn how to code. Make money. Have fun. Enjoy life.
Leaderboard (30-day)
powered by