admin管理员组文章数量:1024603
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
1 Answer
Reset to default 3As 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.
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
1 Answer
Reset to default 3As 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.
本文标签: javascriptquotUncaught ReferenceError Firebase is not definedquotStack Overflow
版权声明:本文标题:javascript - "Uncaught ReferenceError: Firebase is not defined" - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745609692a2158930.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论