I know there have been similar issues to mine, but I'm still a bit stumped on how to secure my Firebase properly.
First, I'm using EmberFire. Second, I'm using Firebase Email/Password authentication for account management. Each of my accounts represents a business. I'd like it so that the currently authenticated business can only access his/her data. Initially, my thinking was to use the following data structure:
+ businesses
- uid-1
- uid-2
- uid-3
...where uid is what's assigned to the user by Firebase email/password authentication. I would then use the following security rules:
{
"rules": {
"businesses": {
"$user_id": {
".read": "$user_id === auth.uid",
".write": "$user_id === auth.uid"
}
}
}
}
With all that said, two questions:
- Will it work? (Pretty sure it will based on this post)
- If so, how can I get EmberFire to allow me to use my own id rather than what's generated by
push()
, which is used by EmberFire under the hood according to the docs.
UPDATE With regards to EmberFire, here's the code I'm using to save my model to Firebase:
var business = _this.store.createRecord('business', {
uid: userData.uid,
businessName: _this.get('businessName'),
firstName: _this.get('firstName'),
lastName: _this.get('lastName')
});
business.save().then(function(success) {
flashMessages.success('Your account has been created! Please login below.');
_this.transitionToRoute('login');
}, function(error) {
flashMessages.warning(error);
});
What I'm seeing is that the root node of these created objects ends up being a unique timestamp ID generated by Firebase. To solve my issue, I'd like to override that to the auth.uid.
Thanks in advance! James
push()
under the hood, so the question is: can I override it so I can use auth.uid as the root node for what I save? – jdixon04