Skip to content

Commit

Permalink
Merge 4db2139 into 6ed1fc1
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestalmage committed Nov 20, 2014
2 parents 6ed1fc1 + 4db2139 commit 78ffd0c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/FirebaseAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
$getAuth: this.getAuth.bind(this),
$requireAuth: this.requireAuth.bind(this),
$waitForAuth: this.waitForAuth.bind(this),
$bindTo:this.bindTo.bind(this),

// User management methods
$createUser: this.createUser.bind(this),
Expand Down Expand Up @@ -188,6 +189,28 @@
return deferred.promise;
},

// Bind the authentication state to a property on scope.
// Returns a deregistration function, which is called automatically when scope is destroyed.
bindTo:function(scope,propertyName){
var ref = this._ref;

function callback(authData){
scope.$evalAsync(function(){
scope[propertyName] = authData;
});
}

function deregister(){
ref.offAuth(callback);
}

scope.$on('$destroy',deregister);

ref.onAuth(callback);

return deregister;
},


/*********************/
/* User Management */
Expand Down

0 comments on commit 78ffd0c

Please sign in to comment.