Save to Firebase using unique userID


#1

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


#2

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


#3

I believe this allows nodes per user in the users path

Just write to it /users//somedata

Got to lerarn firestore too,btw


#4

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


#5

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


#6

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.


#7

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


#8

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

}