Untitled
unknown
plain_text
2 years ago
902 B
8
Indexable
export const writeToRestrictedData = functions.https.onRequest(async (request, response) => {
try {
console.log("body:", request.body);
// const other = '{"message":"hi"}'; //parsing this would work!
const requestData = JSON.parse(request.body); //this is where the error occurs
const message = requestData.message;
if (typeof message !== "string" || message.trim() === "") {
response.status(400).json({error: "Invalid message format"});
return;
}
const data = {
message: message,
// timestamp: db.FieldValue.serverTimestamp(), // Add a timestamp
};
await db.collection("restrictedData").add(data);
response.json({message: "Document written successfully"});
} catch (error) {
console.error("Error:", error);
response.status(500).json({error: "Internal server error"});
}
});Editor is loading...