最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "Uncaught ReferenceError: Firebase is not defined" - Stack Overflow

programmeradmin2浏览0评论

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=".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='.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");
}
}); 

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./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./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");
}
}); 
Share Improve this question edited Jun 18, 2016 at 21:40 Frank van Puffelen 601k85 gold badges890 silver badges860 bronze badges asked Jun 18, 2016 at 20:34 Gregg ClunisGregg Clunis 411 silver badge4 bronze badges 7
  • Probably should omit the key and config info... – Andrew Li Commented Jun 18, 2016 at 20:42
  • @AndrewL Okay thank you. – Gregg Clunis Commented Jun 18, 2016 at 20:46
  • 1 Not from your actual code, just from the site because all this is public :) – Andrew Li Commented Jun 18, 2016 at 20:48
  • 2 You're including version 3.0 of the Firebase SDK for JavaScript, but the code you are using is for version 2.x. Follow the documentation for the new version and the error will disappear. – Frank van Puffelen Commented Jun 18, 2016 at 21:39
  • 1 onAuth() is deprecated in version 3.0 and you no longer instantiate Firebase object the way you did. Frank van Puffelen is right : you should follow the doc of the new version of firebase and you will be good to go. Good Luck! – ALI MAKEEN Commented Jun 19, 2016 at 0:03
 |  Show 2 more ments

1 Answer 1

Reset to default 3

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.

发布评论

评论列表(0)

  1. 暂无评论