首页 > 解决方案 > Uncaught ReferenceError: firebase is not defined, in web application

问题描述

我在我的 Web 应用程序中遇到了一个奇怪的问题。实际上我正在使用 Firebase 托管,并且我正在尝试在我的网页中创建一个“注销”按钮。我说这很奇怪,因为我为登录编写的名为“login.js”的 JavaScript 文件工作正常。但是对于注销功能,它是说“未捕获的 ReferenceError:未定义火力”。

在这里,我发布了我编写的脚本-

HTML-

<div class="subSetingOptionList">
    <button onclick="logOut()">Logout</button>
  </div>

JavaScript-

// ON AUTH STATE CHANGES

firebase.auth().onAuthStateChanged(function(user) {
    if (user) {

        // USER IS SIGNED IN
      document.getElementById("showIfNotLogIn").style.display = "none";
      document.getElementById("onUserLogin").style.display = "block";
        } else {
      // No user is signed in.
      document.getElementById("showIfNotLogIn").style.display = "block";
     document.getElementById("onUserLogin").style.display = "none";
    }
  });

  //THIS PART IS WORKING FOR SURE

function letMeLogin(){


let usernaming = document.getElementById("userNameForLogin").value;
let userpasswording = document.getElementById("userPasswordForLogin").value;

firebase.auth().signInWithEmailAndPassword(usernaming, userpasswording).catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    // ...

    window.alert(`Alert: ${errorMessage}`);
  });

}

//THIS IS THE PART FOR LOGOUT WHICH IS GIVING THE ERROR

    function logOut(){

  firebase.auth().signOut().then(function() {
      // Sign-out successful.
    }).catch(function(error) {
      // An error happened.
   });
  }

标签: javascripthtmlnode.jsfirebase

解决方案


推荐阅读