Save to Firebase using unique userID

// 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

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

I believe this allows nodes per user in the users path

Just write to it /users//somedata

Got to lerarn firestore too,btw

1 Like

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

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

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.

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:

// 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

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();
});

}