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

added support for authWithCustomToken #130

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/backbonefire.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,21 @@

};

/**
* A utility for athenticating with a custom token
*/
Backbone.Firebase._authWithCustomToken = function(model, options) {
if(typeof options !== 'undefined' && typeof options.auth_token !== 'undefined'){
model.firebase.ref().authWithCustomToken(options.auth_token, function(error, authData) {
if (error) {
model.trigger('firebase:login:error', error, null, null);
} else {
model.trigger('firebase:login:success', authData, null, null);
}
});
}
};

/**
* Model responsible for autoSynced objects
* This model is never directly used. The Backbone.Firebase.Model will
Expand Down Expand Up @@ -340,6 +355,9 @@
Backbone.Firebase._throwError('url parameter required');
}

// We handle login with a custom token
Backbone.Firebase._authWithCustomToken(this, options);

if(!this.autoSync) {
OnceModel.apply(this, arguments);
_.extend(this, OnceModel.protoype);
Expand Down Expand Up @@ -818,6 +836,9 @@
throw new Error('url parameter required');
}

// We handle login with a custom token
Backbone.Firebase._authWithCustomToken(this, options);

// if we are not autoSyncing, the model needs
// to be a non-autoSynced model
if(!this.autoSync) {
Expand Down