Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth.onAuthStateChanged is not a function #743

Closed
smrubin opened this issue Jun 2, 2016 · 4 comments
Closed

auth.onAuthStateChanged is not a function #743

smrubin opened this issue Jun 2, 2016 · 4 comments
Assignees

Comments

@smrubin
Copy link

smrubin commented Jun 2, 2016

Version info

Angular: 1.5.5

Firebase: 3.0.3

AngularFire: 2.0.0

Other (e.g. Node, browser, operating system) (if applicable): N/A

Test case / Steps to Reproduce / Actual Behavior

The following code:

myApp.factory("Auth", ["$firebaseAuth",
  function($firebaseAuth) { 
    var ref = firebase.database().ref();    
    var auth = $firebaseAuth(ref);     
    return auth;
  }
]);

is producing the following error:

angular.min.js:formatted:3483TypeError: auth.onAuthStateChanged is not a function
    at https://cdn.firebase.com/libs/angularfire/2.0.0/angularfire.js:1008:20
    at Object.n [as promise] (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js:133:427)
    at Object.FirebaseAuth._initAuthResolver (https://cdn.firebase.com/libs/angularfire/2.0.0/angularfire.js:1001:26)
    at Object.FirebaseAuth (https://cdn.firebase.com/libs/angularfire/2.0.0/angularfire.js:802:38)
    at https://cdn.firebase.com/libs/angularfire/2.0.0/angularfire.js:790:28
    at new <anonymous> (http://localhost:4000/auth/AuthCtrl.js:5:22)
@grosem
Copy link

grosem commented Jun 2, 2016

Simply call $firebaseAuth() as you already initialised the firebase app.

@volodymyr-mykhailyk
Copy link

Just tested. It works with $firebaseAuth() code

@jwngr
Copy link

jwngr commented Jun 2, 2016

As of AngularFire 2.0.0, the $firebaseAuth service now takes an instance of the Firebase auth service, not a Firebase database reference. So, try this instead:

var auth = firebase.auth();
var authService = $firebaseAuth(auth);

As alluded to above, if you have already initialized the Firebase SDK via firebase.initializeApp(), you can simply call $firebaseAuth() with no parameters and we will call firebase.auth() on your behalf:

// If firebase.initializeApp() already called
var authService = $firebaseAuth();

@AbeHaskins is putting together a PR which spits out a better error message for this and we should cut a 2.0.1 release sometime today with that change. He'll also update the migration guide to include this slight change in behavior. The code above should resolve your issue though.

@jwngr
Copy link

jwngr commented Jun 2, 2016

Updated error message went out with the 2.0.1 release.

@jwngr jwngr closed this as completed Jun 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants