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?