Skip to content
This repository has been archived by the owner on Aug 25, 2018. It is now read-only.

Idea about autoSync conflicting with Firebase rules #132

Closed
cdcarson opened this issue Jan 6, 2015 · 2 comments
Closed

Idea about autoSync conflicting with Firebase rules #132

cdcarson opened this issue Jan 6, 2015 · 2 comments

Comments

@cdcarson
Copy link

cdcarson commented Jan 6, 2015

Thanks for the great library.

I'm coming up against a minor (and perhaps fixable in future) problem. Let's say I have a firebase reference at some.firebase.io/options. My rules say that everybody can read this reference, but only admin users can write to it, something like this:

{
    "rules": {
        ".read": false,
        ".write": false,
        "options": {
          ".read": true,
          ".write": "root.child('users').child(auth.uid).child('type').val() >= 3"
        }
    }
}

For "admin" users there's no problem, but for other users who can't write to the reference there's a Firebase warning when page first loads:

FIREBASE WARNING: update at /options failed: permission_denied 

I understand that this is as it should be -- that Firebase is obeying my rules. I also understand that the warning is not a huge problem, but I hate warnings, so...

What (I think) happens now, and results in the warning, is that backbonefire automatically tries to create a model on the server. Might there possibly be a way to say that you just want to fetch an existing model from the server? Something like this:

var MyModel = Backbone.Firebase.Model.extend({
   url: myReference,
   readFirst: true
})

In other words autoSync would still be enabled, but if readFirst is true, then the model is initially populated from the server. My app can allow a user to modify the model afterwards, and those changes would be synced. The initial behavior of collections could be modified in the same way.

Sorry for the lengthy post about a minor problem. Let me know what you think,

-- Chris

@davideast
Copy link
Contributor

Hey Chris,

Thanks for sending in your thoughts.

We actually were discussing something like a readFirst type functionality the other day. I've been toying with the idea of providing control over specific syncing events. This would cover your typical Firebase events (value, child_added, child_removed) as well as the initial sync, which is what you're looking for.

This way you would be able to do any custom operations like joining the result of two references or canceling a connection when a user is not properly authenticated.

I don't have an API to reference here, but I'll see if I can come up with some ideas in the next couple of days.

@davideast
Copy link
Contributor

See #134

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants