Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 3694e15

Browse files
committed
Fixes #510 - call onAuth() listeners in $digest scope
1 parent 2339075 commit 3694e15

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/FirebaseAuth.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,12 @@
195195
onAuth: function(callback, context) {
196196
var self = this;
197197

198-
this._ref.onAuth(callback, context);
198+
var fn = this._utils.debounce(callback, context, 0);
199+
this._ref.onAuth(fn);
199200

200201
// Return a method to detach the `onAuth()` callback.
201202
return function() {
202-
self._ref.offAuth(callback, context);
203+
self._ref.offAuth(fn);
203204
};
204205
},
205206

tests/unit/FirebaseAuth.spec.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,21 @@ describe('FirebaseAuth',function(){
270270
});
271271

272272
describe('$onAuth()',function(){
273-
it('calls onAuth() on the backing ref with callback and context provided',function(){
274-
function cb(){}
273+
//todo add more testing here after mockfirebase v2 auth is released
274+
275+
it('calls onAuth() on the backing ref', function() {
276+
function cb() {}
275277
var ctx = {};
276-
auth.$onAuth(cb,ctx);
277-
expect(ref.onAuth).toHaveBeenCalledWith(cb, ctx);
278+
auth.$onAuth(cb, ctx);
279+
expect(ref.onAuth).toHaveBeenCalledWith(jasmine.any(Function));
278280
});
279281

280-
it('returns a deregistration function that calls offAuth() on the backing ref with callback and context',function(){
281-
function cb(){}
282+
it('returns a deregistration function that calls offAuth() on the backing ref', function(){
283+
function cb() {}
282284
var ctx = {};
283-
var deregister = auth.$onAuth(cb,ctx);
285+
var deregister = auth.$onAuth(cb, ctx);
284286
deregister();
285-
expect(ref.offAuth).toHaveBeenCalledWith(cb, ctx);
287+
expect(ref.offAuth).toHaveBeenCalledWith(jasmine.any(Function));
286288
});
287289
});
288290

0 commit comments

Comments
 (0)