Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70440

CORS Error when running App on Real Device

$
0
0

@bmcgowan94 wrote:

Hi guys, Im using a firebase cloud function (code shown below) which basically updates the number of likes on a particular post (its for a social media app).

/* this cloud function is used to update the likes on a post
- it receives three parameters in the post body 
- and will update those respective fields in the post document (e.g number of likes)
*/

export const updateLikesCount = functions.https.onRequest((request, response) => {

  const postId = JSON.parse(request.body).postId;
  const userId = JSON.parse(request.body).userId;
  const action = JSON.parse(request.body).action; // 'like' or 'unlike' 

  // from this data object we can get the value of all the fields in the document
  admin.firestore().collection("posts").doc(postId).get().then((data) => {

    // if likes counts = 0, then assume there are no likes 
    let likesCount = data.data().likesCount || 0;
    // likewise if there are no likes, then assign an empty array
    let likes = data.data().likes || [];

    let updateData = {};

    if(action == "like")
    {
      updateData["likesCount"] = ++likesCount;
      updateData[`likes.${userId}`] = true;
    } 
    else 
    {
      updateData["likesCount"] = --likesCount;
      updateData[`likes.${userId}`] = false;
    }

    admin.firestore().collection("posts").doc(postId).update(updateData).then(() => {
      response.status(200).send("Done")
    }).catch((err) => {
      response.status(err.code).send(err.message);
    })

  }).catch((err) => {
    response.status(err.code).send(err.message);
  })

})

When the app is running and the ‘like’ button is pressed, I get this console error…

Please help, I cant seem to find many answers online, and the solutions I do find don’t seem to work for me. Many thanks! :slight_smile:

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70440

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>