I have to create a social network project equivalent to facebook and I am in the process of publishing a message on the administrator’s profile, on his friend’s profile as well as on all profiles using boostrap 5 and following instructions that I am asked to make. I am in the process of posting messages on the profile and I am blocked when the administrator publishes a message about any member. In the browser when I try to post a “Hello” I get an error message telling me POST http://localhost:3000/api/postAllProfiles 403 (Forbidden)
(anonymous) and Error while publishing the message: Error: Error while publishing the message
at HTMLFormElement.<anonymous. Apparently my mistake would come from the scripts.js side on this part
your text
//// Form to post a message to all the administrator’s profiles..
document.addEventListener("DOMContentLoaded", function () {
const postAllProfilesForm = document.getElementById("postAllProfilesForm");
const allProfilesMessagesList = document.getElementById(
"allProfilesMessagesList"
);
postAllProfilesForm.addEventListener("submit", async function (event) {
event.preventDefault();
const message = document.getElementById("postAllprofilesMessage").value;
try {
const response = await fetch(
"http://localhost:3000/api/postAllProfiles",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: Bearer ${localStorage.getItem("token")},
},
body: JSON.stringify({ content: message }),
}
);
if (!response.ok) {
throw new Error("Erreur lors de la publication du message");
}
const data = await response.json();
alert("Message publié avec succès sur tous les profils !");
postAllProfilesForm.reset();
loadAllProfilesMessages();
} catch (error) {
console.error("Erreur lors de la publication du message : ", error);
alert("Erreur lors de la publication du message : " + error.message);
}
``` But I can't find what's wrong. Can you please help me find the solution? Thank you all. Best regards