“Uncaught ReferenceError: Firebase is not defined”

耗尽温柔 提交于 2019-12-07 09:00:29

问题


I'm working with Firebase for the first time on a practice project and I'm having a very difficult time setting up the ability for users to log in to their accounts.

I've successfully set up registration but so far I can't get log in and check auth state to work properly.

The error I keep receiving in the console is "Uncaught ReferenceError: Firebase is not defined"

I've done some research on my own but the only answers I seem to find are ones saying you need to include the script tags for Firebase, which isn't relevant here because I have included them, or outdated responses from version 2.4.2

<head>
<script src="https://www.gstatic.com/firebasejs/3.0.5/firebase.js"></script>

<script>
   /*global Firebase */
  // Initialize Firebase
  var config = {
    apiKey: "omit",
    authDomain: "omit",
    databaseURL: "omit",
    storageBucket: "omit",
  };
  firebase.initializeApp(config);
</script>

<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>

The code in question is here:

// Create a callback which logs the current auth state
var ref = new Firebase("omit");
ref.onAuth(function(authData) {
if (authData) {
console.log("User " + authData.uid + " is logged in with " + authData.provider);
} else {
console.log("User is logged out");
}
}); 

回答1:


As Frank van Puffelen pointed out, and as per the Firebase documentation, in Firebase 3.x, the root database reference is instantiated as firebase.database().ref() and not as new Firebase("<path>");. This should solve the uncaught reference error.

Fixing it will, of course, be followed by other errors in your code, as ALI MAKEEN pointed out. Refer the latest documentation. BTW, if you're using AngularJS, AngularFire is an excellent binding for Firebase, and it supports user authentication.



来源:https://stackoverflow.com/questions/37901409/uncaught-referenceerror-firebase-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!