-
Notifications
You must be signed in to change notification settings - Fork 77
Provide customization of initial data sync #134
Comments
It would be awesome with a hook to handle different scenarios before sync, and perhaps a good name for the function could be This would make it possible to authenticate, but what I like about the solution I proposed in #130 is that it reduces the amount of boilerplate code you have to write. I also liked the fact that it communicated with the world through events, which would make it possible for me to create a parent view to handle authentication and errors in my views. So I would opt for introducing this hook as well as also implementing authentication :-) Perhaps something similar to this to accomodate more than just custom auth: var authSettings = {
provider: 'custom|password|anonymous',
credentials: { // used with password provider
email: "email",
password: "password"
remember: "default|sessionOnly|none"
},
token: 'token' // used with custom provider
}
// Then you could add authSettings to the Model/Collection by extending
var Todo = Backbone.Firebase.Model.extend({
auth: auth
});
// or pass them when you create a new Instance?
var model = new Todo({}, {
auth: auth
}); And of course model/collections fire the appropriate events collection.on('firebase:login:success', function(authData){
// handle success
});
collection.on('firebase:login:error', function(error){
// handle error
}); |
This wouldn't be the total solution for authentication. It would be the platform to create customized models and collections that handle auth, like yours does. I'd like to keep BackboneFire as flexible as possible. You can always |
Closing in favor of #133 |
In the current version of BackboneFire data is automatically synced when an
autoSync
model or collection is created.This can cause problems for authenticated or queried references. It would be nice to have a way to do some custom logic on a reference after it is created, but before the data is synced. This way a query can be placed on the reference or even authentication can happen. This would provide flexibility over setting custom options for authentication and querying.
Example API
For those we do not with to sync immediately we could simply return false:
If you have thoughts on this, please let me know. I'm not a fan of the
preInit
name right now, but it is the best I can think of to illustrate the idea.The text was updated successfully, but these errors were encountered: