From 5d1529dd8c6c30b07da5dd03130400c5a0b7d144 Mon Sep 17 00:00:00 2001 From: Troels Johnsen Date: Tue, 6 Jan 2015 07:42:37 +0100 Subject: [PATCH] added support for authWithCustomToken --- src/backbonefire.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/backbonefire.js b/src/backbonefire.js index ddfb0b7..97e49b3 100644 --- a/src/backbonefire.js +++ b/src/backbonefire.js @@ -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 @@ -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); @@ -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) {