2

I have a list of acceptable jobs that a user request (user 1) from their interface and those acceptable jobs are shown to user 2 who can accept those jobs or none at all. Now I have it saving under the specific city from the request, however, within the city node I want it to save under their user ID when they hit the accept button. Therefore, within their UID, the contents of the job will list all its details.

I can't seem to get it working fully.

My JS snippet:

var ref = firebase.database().ref('requests');
var ref2 = firebase.database().ref('Providers').child("City").child("Cincinnati");

ref.on('value', function(snapshot) {
   ref2.set(snapshot.val(), function(error) {

   });
});

So we're showing the provider the initial request with limited info (which has a ton of info). Once they click 'accept', they're able to view all the info but I'm currently just copying that info into another snapshot.

My question:

How can I save the info under their signed in, user ID (UID)?

The tree is set up like so:

Providers
    City
       Cincinnati
          UID
            Job Key ID
               Job Details
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
mur7ay
  • 803
  • 3
  • 16
  • 44
  • User #2 is able to accept multiple jobs which is why I'm wanting to save under their UID – mur7ay Jun 05 '18 at 18:16
  • Possible duplicate of [How do I link each user to their data in Firebase?](https://stackoverflow.com/questions/30910704/how-do-i-link-each-user-to-their-data-in-firebase) – André Kool Jun 06 '18 at 09:23

1 Answers1

3

To save data under userid, get the userid first:

var user = firebase.auth().currentUser;
var uid=user.uid;

then save the data under the uid:

var ref2 = firebase.database().ref('Providers').child("City").child("Cincinnati");
ref2.child(uid).set({
jobDetails:details
});

more info here:

https://firebase.google.com/docs/database/web/read-and-write

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134