未捕获的TypeError:firebase.auth不是函数 [英] Uncaught TypeError: firebase.auth is not a function

查看:69
本文介绍了未捕获的TypeError:firebase.auth不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用firebase(电子邮件和密码)构建身份验证应用程序,但使用firebase方法存在问题. 当我调用firebase.auth时,他们说这不是一个函数".是因为我的项目和Firebase SDK没有链接?

I try to build an authentification app with firebase (email & password) but i have problem with firebase methods. When I call firebase.auth, they said "it's not a function". Is it because my project and firebase SDK are not linked ?

您有什么建议吗? :)

Do you have some suggestions ? :)

<!doctype html>
<html lang="fr">
  <head>
  <meta charset="utf-8">

  <!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.6.0/firebase-app.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use
     https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.6.0/firebase-analytics.js"></script>

<script>
  // Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "secret",
    authDomain: "secret",
    databaseURL: "secret",
    projectId: "secret",
    storageBucket: "secret",
    messagingSenderId: "secret",
    appId: "secret",
    measurementId: "secret"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.analytics();
</script>

  <!--Stylesheet CSS --> 
  <link rel="stylesheet" href="../css/main.css">

      <title>Inscription</title>

</head>

<body>

  <form id="formSignUp" method="POST" onsubmit="signUp()">
    <input type="text" id="form_input_mail" name="mail" placeholder="E-mail" size= "30">
    <input type="password" id="form_input_password" name="password" placeholder="Mot de passe" 
      size= "30">
    <button type="submit" id="button_orange_center"> Suivant</button>
  </form>
  <script>
      function signUp(){
      firebase.auth().createUserWithEmailAndPassword(form_input_mail, form_input_password)
    .catch(function(error) {
  // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    if (errorCode == 'auth/weak-password') {
      alert('The password is too weak.');
    } else {
      alert(errorMessage);
    }
    console.log(error);
  });
}
  </script>

</body>
</html>

推荐答案

Firebase产品(例如Auth)也需要从CDN下载

Firebase products (eg. Auth) also need to be downloaded from the CDN

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

参考: https://firebase.google.com/docs/web/setup

这篇关于未捕获的TypeError:firebase.auth不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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