# Save to Firebase using unique userID

**URL:** <https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240>\
**Category:** ionic-v3\
**Created:** [December 22, 2017, 6:29pm UTC](https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240 "2017-12-22T18:29:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Louis101](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@Louis101](https://forum.ionicframework.com/u/Louis101)\
**Post date:** [December 22, 2017, 6:29pm UTC](https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240/1 "2017-12-22T18:29:31Z")

</div>

// These rules grant access to a node matching the authenticated  
// user’s ID from the Firebase auth token  
{  
“rules”: {  
“users”: {  
"$uid": {  
".read": “$uid === auth.uid”,  
".write": “$uid === auth.uid”  
}  
}  
}  
}

This doesnt grant a user permission to read or write? However, I would like each user to have their own Node, any help would be great thanks

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [December 22, 2017, 6:31pm UTC](https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240/2 "2017-12-22T18:31:37Z")

</div>

You’re better off learning the Firestore rules, unless you have a special reason you need Firebase.

---

<div class="post-metadata">

**Author:** ![Tommertom](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tommertom](https://forum.ionicframework.com/u/Tommertom)\
**Post date:** [December 22, 2017, 8:09pm UTC](https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240/3 "2017-12-22T20:09:10Z")

</div>

I believe this allows nodes per user in the users path

Just write to it /users//somedata

Got to lerarn firestore too,btw

---

<div class="post-metadata">

**Author:** ![Louis101](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@Louis101](https://forum.ionicframework.com/u/Louis101)\
**Post date:** [December 23, 2017, 7:38pm UTC](https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240/4 "2017-12-23T19:38:50Z")

</div>

I have started reading firestore, however I am a little unsure to your answer?

---

<div class="post-metadata">

**Author:** ![Tommertom](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tommertom](https://forum.ionicframework.com/u/Tommertom)\
**Post date:** [December 25, 2017, 6:11pm UTC](https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240/5 "2017-12-25T18:11:37Z")

</div>

Hi  
sorry about that.

I meant to say your firebase rules suggestion suffices to write user node specific data.

And after I read through Firestore, the day before yesterday, I think @AaronSterling has the best suggestion for you, unless you don’t like the Beta-ness of Firestore.

I reckon Google is going to abandon Firebase over Firestore because it is just the next level of it.

I am going to prefer Firestore of Firebase anyway

---

<div class="post-metadata">

**Author:** ![Louis101](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@Louis101](https://forum.ionicframework.com/u/Louis101)\
**Post date:** [December 26, 2017, 7:00pm UTC](https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240/6 "2017-12-26T19:00:17Z")

</div>

Hi,

Hope you’re well.

I have now changed over to Firestore but I am still unser after reading how to save by a unique userId?

Any help would be appreciated, thank you.

---

<div class="post-metadata">

**Author:** ![Tommertom](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tommertom](https://forum.ionicframework.com/u/Tommertom)\
**Post date:** [December 27, 2017, 7:41pm UTC](https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240/7 "2017-12-27T19:41:40Z")

</div>

Hi

something like

`db.collection('users').doc(uid).set({stuff:'data'})`

Where uid is the uid you collect from the authentication steps.

With rules setup as per documentation:

```auto
// Grants a user access to a document matching their Auth user Id
service cloud.firestore {
  match /databases/{database}/documents {
    // Collection named "users", document named after the userId
    match /users/{userId} {
      allow read, write: if request.auth.uid == userId;
    }
  }
}

```

Not tried it myself, but i guess this should be about it

Just give it a try and read the docs

---

<div class="post-metadata">

**Author:** ![Louis101](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@Louis101](https://forum.ionicframework.com/u/Louis101)\
**Post date:** [January 2, 2018, 2:56pm UTC](https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240/8 "2018-01-02T14:56:33Z")

</div>

export class SignupPage {  
signupData = {  
email: ‘’,  
password: ‘’,  
passwordRetyped: ‘’  
};

constructor(private navCtrl: NavController, private navParams: NavParams, private alertCtrl: AlertController,  
private afAuth: AngularFireAuth) {  
this.signupData.email = this.navParams.get(‘email’);  
}

signup() {  
if(this.signupData.password !== this.signupData.passwordRetyped) {  
let alert = this.alertCtrl.create({  
title: ‘Error’,  
message: ‘Your password and your re-entered password does not match each other.’,  
buttons: [‘OK’]  
});  
alert.present();  
return;  
}  
// Firebase Signup Code  
this.afAuth.auth.createUserWithEmailAndPassword(this.signupData.email, this.signupData.password)  
.then(auth =\> {  
// Could do something with the Auth-Response  
console.log(auth);  
})  
.catch(err =\> {  
// Handle error  
let alert = this.alertCtrl.create({  
title: ‘Error’,  
message: err.message,  
buttons: [‘OK’]  
});  
alert.present();  
});

}

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:57pm UTC](https://forum.ionicframework.com/t/save-to-firebase-using-unique-userid/116240/9 "2021-07-19T21:57:44Z")

</div>


