“message”: “Unauthorized Access” when i post something on my input form post is working correctly but when I wanted to get that thing http://localhost:5000/my it’s showing “message”: "Unauthorized Access
serverSide Code IS:
app.post("/order", async (req, res) => {
const my = req.body;
const result = await myCollection.insertOne(my);
res.send(result);
});
app.get("/order", async (req, res) => {
const query = {};
console.log(query);
const cursor = myCollection.find(query);
const services = await cursor.toArray();
res.send(services);
});
Client side code is:
const onSubmit = (data, event) => {
const url = `http://localhost:5000/service`;
fetch(url, {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify(data),
})
.then((res) => res.json())
.then((result) => {
setIsReload(!isReload);
if (result) {
alert("Add Successful");
}
});
const order = {
email: user.email,
name: event.target.name.value,
description: event.target.description.value,
price: event.target.price.value,
quantity: event.target.quantity.value,
};
axios.post(`http://localhost:5000/order`, order).then((res) => {
const { data } = res;
console.log(data);
if (data.insertedId) {
alert("Inserted");
}
event.target.reset();
console.log(res);
});