“未捕获的引用错误:未定义Firebase” [英] "Uncaught ReferenceError: Firebase is not defined"

查看:311
本文介绍了“未捕获的引用错误:未定义Firebase”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个实践项目中首次与Firebase合作,并且在设置用户登录帐户方面遇到了困难。



我已成功设置注册,但到目前为止我无法登录并检查auth状态以正常工作。



我一直收到的错误控制台是
未捕获的ReferenceError:未定义的Firebase

我对自己做了一些研究,但似乎找到的唯一答案是说你需要包含Firebase的脚本标签,这是因为我已经包含它们,或从2.4.2版本过时的响应这里是不相关的

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

< script>
/ *全局Firebase * /
//初始化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>

有问题的代码在这里:

  //创建一个记录当前认证状态的回调
var ref = new Firebase(omit);
ref.onAuth(function(authData){
if(authData){
console.log(User+ authData.uid ++authData.provider));
} else {
console.log(User is logged out);
}
});


解决方案

正如Frank van Puffelen指出的那样,在Firebase 3.x中 Firebase文档中,实例化根数据库引用() firebase.database()。ref() 。这应该解决未捕获的引用错误。



正如ALI MAKEEN指出的那样,修正这个错误当然会在代码中出现其他错误。请参阅最新的文档。顺便说一句,如果你使用的是AngularJS,AngularFire是一个很好的Firebase绑定,它支持 user authentication


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

解决方案

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.

这篇关于“未捕获的引用错误:未定义Firebase”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆