The data is saved into an Event and a unique Push key is generated. However, there seems to be an issue when assigning the Event key to the EventList in Firebase

Some data was saved under the event tag, and the Location/Key is required for user reference. I attempted to save user/eventlist { ref : Event_Key }, but encountered an error when trying to concatenate with a string.

Console Output:

OnSubmit Working
Postjobc.js:11 getLocation Working
Postjobc.js:47 First Condition Ok : undefined
Postjobc.js:68 0
Postjobc.js:23 Eventinsert Working :-MF0_ZKTuNdiN0QbIjbd    (I get key )
Postjobc.js:18 position Working
logger.ts:115 [2020-08-18T12:41:19.218Z]
@firebase/database:
FIREBASE WARNING: set at /users/userId/eventlist/-MF0_berJy7yKkaZvS-G failed: permission_denied 

Firebase Rules:

"rules": {
"users": {
  "$uid": {
    ".read": "$uid === auth.uid",
    ".write": "$uid === auth.uid"
          }
        },
"jobpost":{
  "events":{
    ".read" : "auth.uid != null",
     ".write": "auth.uid != null"
  }

Real Time Database:

-https://Project.firebaseio.com/celebrity_program/
   -events

             -MppF9d5aIkhia2u5kka  (Event_key)
    -user   
       -$uid
         
           -eventList
                -Mdhhshhsheuer 
                    eventref: Event_Key

Case 1:

const Eventinsert = () => {
    var EventsId = Firebase.database().ref('events/').push({
        Title: Title,
        Role: Role,
        Location: Location,
        Description: Description,
        SelectionBy: SelectionBy
    })

    var str = EventsId.key;
    var loo = true;
    do {
        if (typeof str !== undefined) {
            console.log(str);                [console output val= -MErnwYwknRZz5MFH ]     
            EventListInsert(str);
            loo = false;
        }
    } while(loo)
  } 

  EventListInsert(Key){
      console.log(key);           [console output: key=-MErnwYwknRZz5MFH ]
        var userId = localStorage.getItem("User");    
         var d = new Date();
        Firebase.database().ref('user/UserId/eventlist/').push({
           event: Key,
            latitude: la,
            longitude: lo,
            date: d
      })
     }

  }

An error occurred as "Error: Reference.push failed: first argument contains undefined in property 'eventlist.event"

Case 2:

const Eventinsert = () => {
    var EventsId = Firebase.database().ref('events/').push({
        Title: Title,
        Role: Role,
        Location: Location,
        Description: Description,
        SelectionBy: SelectionBy
    })

    var str = EventsId.key;
    var loo = true;
    do {
        if (typeof str !== undefined) {
            var val= "str" + str;
            console.log(val);                [console output val= str-MErnwYwknRZz5MFH ]     
            EventListInsert(val);
            loo = false;
        }
    } while(loo)
  }
  var userId = localStorage.getItem("User");
  function EventListInsert( Key ){
      var d = new Date();
        Firebase.database().ref('user/UserId/eventlist/').push({
          
            event: Key,
            latitude: la,
            longitude: lo,
            date: d
      })
     }

The same error occurred as "Error: Reference.push failed: first argument contains undefined in property 'eventlist.event"

If I remove event: Key,, it runs successfully and adds the event to the database. However, the user requires a reference to know which post I'm referring to. How can this be resolved? Is there another way to create a reference?

Answer №1

the issue suggests that the event attribute might possibly not be defined. Checking for typeof str !== undefined doesn't accurately determine if the string is undefined. A more reliable approach would be to simply verify if str has a value by using if(str).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to navigate to a different page using HTML response from an AJAX request

After receiving an HTML document as a response from an AJAX call, I need to create a redirection page using this HTML response. Can anyone provide guidance on how to achieve this? ...

Fullcalendar Bootstrap popover mysteriously disappears

I'm having issues with my Bootstrap popovers being hidden under the rows in FullCalendar. I've tried using container: 'body' and trigger: 'focus', but they don't seem to work. The function that's causing this proble ...

I possess both a minimum and maximum number; how can I effectively create an array containing n random numbers within

Given a minimum number of 10.5 and a maximum number of 29.75, the task is to generate an array within these two ranges with a specific length denoted by 'n'. While the function for generating the array is provided below, it is important to calcul ...

Discover a method to obtain the indexof() starting from the last character of a string

I'm wondering how to determine the number of characters after the "|" symbol in this string: "354-567-3425 | John Doe". I did some research and only came across the javascript indexOf() method. While this method is useful for finding characters before ...

Transforming the navigation menu using CSS, HTML, and jQuery

One challenge I am facing involves creating a menu similar to the one on http://edition.cnn.com/. I want the clicked button in the menu to receive focus, while the others lose it. Despite trying various methods, I have not been successful. Can someone off ...

How to utilize JS variables for filtering an array in EJS?

Is there a way to filter my user array based on the "username" variable in JavaScript? On the server side: var users = data.filter(u => u.id.startsWith('user_')).map(u => u.value); // [{"username": "arin2115", "som ...

The select element becomes visible once the data has been received

My HTML table includes a column labeled "Mortgage Type" that allows users to edit the field by selecting a dropdown value and entering text into an input field. The default value in the Mortgage Type dropdown list is "Auto". When the user enters data in ce ...

A guide on fetching an array of data from an AJAX request

In my quest to retrieve an array of values within an ajax success method, I have encountered a dilemma... Below is the snippet of my ajax code: $.ajax({ url: '/Workflows/NumberofWorkflows', type: 'GET', async: false, ...

Using .slice in combination with a media query allows you to specify different subsets

Is there a way in React to only slice objects when the screen width is 600px or less? Here's the code I'm currently using to determine the screen size: const [matches, setMatches] = useState( window.matchMedia("(max-width: 600px)").matches ) ...

Is there a way to calculate the word frequency in my text using plain JavaScript?

Welcome to the text entry section: https://i.sstatic.net/VlBvt.png After clicking on the COUNT button, it will direct you to this page: https://i.sstatic.net/sqKWc.png I can see my entered text and word count displayed. Now I'm curious, how can I ...

The canvas grid is malfunctioning and failing to display correctly

My current code allows me to draw a grid on a canvas with multiple lines, but I'm encountering an issue when trying to render 25 or more lines - some of them don't appear on the canvas. This problem becomes more noticeable when there are 40 or mo ...

Following the ajax request, the subsequent code was unable to be executed as it awaited the JSON response

My latest project involves using Django2 to create a web application. I encountered an issue in the frontend where, despite receiving a 200 status code in the network tab after an ajax call, no alert box was displayed. The app seemed to be stuck at a parti ...

Tips for regularly retrieving information from a psql table

I have a scenario where I am retrieving data from a psql table and converting it into a JSON array to be used for displaying a time series chart using JavaScript. The data that is passed needs to be in the form of an array. Since the data in the table get ...

What happens when Google Polymer platform is used without defining _polyfilled?

My attempt at creating a simple example using Google Polymer's platform.js is running into an error message that says: Uncaught TypeError: Cannot read property '_polyfilled' of undefined This is what I'm attempting to achieve: <cur ...

Separate the express node js into a pair

I'm attempting to divide a code into two parts using express. Here is how I approached it: app.js var express = require('express'); var app = express(); var stud = require('./grades'); var port = process.env.PORT || 3000; stud. ...

Troubleshooting problems with dynamic elements and qTip

On my page, I have an UpdatePanel where new forms are added when clicked. These new elements contain images that need to utilize qTip. This is the current setup: $(document).ready(function () { $('.ttip').qtip({ conten ...

Customized HTML Template Tag

While I understand that using custom html tags is generally frowned upon for various reasons, I have a specific scenario that I believe might warrant the use of a custom html tag. I hope to either be proven wrong or discover a better way of achieving my ob ...

Determining the emptiness of an array in Postman using node.js

When I receive a response, it is in the following format: { "test1": [], "test2": [], "test3": [], "test4": null, "test5": [] } This is the response that I get after making a request. I need to verify whether test1 is empty or not. ...

Issue with clearing input field after submitting form (React)

I'm struggling to get the input field to clear automatically after clicking the submit button in my React component. I've tried making it fully controlled by React, where the input value depends solely on the state, but I can't seem to figur ...

What is causing my JavaScript not to load properly within Bootstrap tabs?

I am facing an issue with my website which has Bootstrap 4 tabs implemented in a blade template. The problem arises when there are tabs within tabs, and upon clicking one tab, the slicks Javascript plugin that I created does not load on other tabs. It on ...