Please provide the following:
- SDK Version:46
- Platforms(Android/iOS/web/all):all
- Add the appropriate “Tag” based on what Expo library you have a question on.
Hi, i currently have an Expo App, when app opens i get the users permission to send notifications and store both their expo push token and device push token in my firestore database.
I also, have a react app where i want to send these users a notification. In my web app, i have 2 input boxes 1 for title and the other for body. When i try sending them i keep getting error code 400, i tried adding a proxy in the web app and still the same error occurs.
Here is my code
const message = {
to: tokens,
sound: "default",
priority:'normal',
data: {
experienceId: '@owner/slug',
scopeKey: '@owner/slug',
title: title,
message: body,
},
};
const response = await fetch('https://fcm.googleapis.com/fcm/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `key=${process.env.REACT_APP_FCM_SERVER_KEY}`,
},
body: JSON.stringify(message),
});
console.log(response)
if(response.ok){
try {
const docRef = await addDoc(collection(db, "broadcast"), {
title: title,
body:body,
tokens:tokens
});
console.log("Document written with ID: ", docRef.id);
toast.success(`broadcast ${title} sent.`, {position: "top-right",})
} catch (e) {
console.error("Error adding document: ", e);
toast.error(e, {position: "top-right",})
}
}