简体   繁体   English

尝试使用 Firebase Auth 时出现错误

[英]I get an Error when I try to use Firebase Auth

I'm Building my first time a website thats include firebase (firebase auth).我第一次建立一个包含 firebase(firebase auth)的网站。 I get an Error when I run my HTML Code in the Browser.在浏览器中运行 HTML 代码时出现错误。

Uncaught TypeError: firebase.auth is not a function at HTMLButtonElement.未捕获的类型错误:firebase.auth 在 HTMLButtonElement 中不是 function。 (app.js:24) (app.js:24)

I dont find any articels too this issue.我也没有找到任何文章这个问题。 I've already reinstalled node and the firebase tools.我已经重新安装了节点和 firebase 工具。 Has anybody an answer for me, I really dont know whats to do... Heres my Index.html file and my App.js File Index.html:有没有人回答我,我真的不知道该怎么办......这是我的Index.html文件和我的App.js文件Index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Log In Page</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js"></script>
</head>
<body>
    <div class="Main-Div">
        <h3 class="Headline">
            Do you have an Account?
        </h3>
        <input type="text" placeholder="Your Email..." class="AccountInput" type="email" id="txtemail">
    </br>
        <input type="text" placeholder="Your Passcode..." class="AccountInput" type="Password" id="txtpassword">
    </br>
        <button class="LogInButton" id="1Button">Log In</button>
        <button class="SignUpButton" id="2Button">Sign Up now!</button>
        <button class="LogOutButton" id="3Button">Log Out</button>
    </div>
    <script src="app.js"></script>
</body>
</html>

And here my other File, App.js: (i've censored the datas about my firebase-database)这里是我的另一个文件 App.js:(我已经审查了有关我的 firebase-database 的数据)

(function(){
const firebaseConfig = {
    apiKey: "Censored",
    authDomain: "Censored",
    projectId: "Censored",
    storageBucket: "Censored",
    messagingSenderId: "Censored",
    appId: "Censored"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);

// Get Elements
  const txtEmail = document.getElementById('txtemail');
  const txtPassword = document.getElementById('txtpassword');
  const btnLogIn = document.getElementById('1Button');
  const btnSignUp = document.getElementById('2Button');
  const btnLogOut = document.getElementById('3Button');

  btnLogIn.addEventListener('click', e => {
    const email = txtEmail.value;
    const password = txtPassword.value;
    const auth = firebase.auth();

    const promise = auth.signInWithEmailAndPassword(email, pass);
    promise.catch(e => console.log(e.message));
  });

}());

Thanks for your attention Greetings Max感谢您的关注 Greetings Max

In index.html you imported only the core firebase library firebase-app.js in order to use a firebase service (firestore/storage etc) in your web app, you need to import that respective service from a CDN. In index.html you imported only the core firebase library firebase firebase-app.js in order to use a firebase service (firestore/storage etc) in your web app, you need to import that respective service from a CDN.

in your case, you need to add firebase-auth.js in your <head></head>在您的情况下,您需要在<head></head>中添加firebase-auth.js

here is the link链接在这里

<script src="https://www.gstatic.com/firebasejs/8.2.8/firebase-auth.js"></script>

in this page you can find all of the services CDNs在此页面中,您可以找到所有服务 CDN

also you need to go to your project's firebase dashboard and enable password authentication as stated in this documentation您还需要 go 到您项目的 firebase 仪表板并启用密码身份验证,如本文档中所述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么当我尝试使用 firebase 使用 React 登录 google 时会出现网络错误 - Why do I get network error when I try to use firebase to sign in with google using React 我正在使用firebase进行用户身份验证,但是当我尝试编写一个语句以在登录时显示一个页面而不是我得到一个钩子错误并且它不会显示 - I am using firebase for user auth but when i try to write a statement to show one page when its logged in and not i get a hook error and it wont show 当我尝试从 firebase 获取数据时,控制台出现错误 - when I try to get a data from the firebase I get error in the console React - 当我尝试导入“firebase/app”时出现 Firebase 模块错误 - React - Firebase module error when i try to import 'firebase/app' 当我尝试使用“.remove()”时出现错误 - Getting an error when I try to use ".remove()" 我尝试使用Grunt时出现语法错误 - Syntax Error When I Try to Use Grunt 当我尝试切换到firestore并添加新的脚本标签时,firebase.auth()无法正常工作 - firebase.auth() not working when I try to switch to firestore and added new script tag 为什么在尝试使用自定义指令时出现错误。 - Why I get error when I try to use custom directive. 当我尝试在Google脚本中使用数组映射函数时出现语法错误。 为什么? - I get a syntax error when I try to use array map function in Google Scripts. Why? 当我尝试使用cropperJS获得50%的图像时出现错误 - I get the error when i try get 50% of the image with cropperJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM