本文介绍了解决方法:无法读取未定义的属性"GoogleAuthProvider"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase进行身份验证,但是在设置时遇到了一些麻烦

I'm using firebase for authentication purposes but i'm having some troubles setting it up

我已经尝试了教程中提到的所有内容,但没有成功

I already tried everything the tutorial said but to no success

https://www.youtube.com/watch?v=hb85pYZSJaI

  <body>
    <div id="firebaseui-auth-container"></div>
  </body>

  <!-- firebase -->
  <script src="https://www.gstatic.com/firebasejs/6.2.4/firebase-app.js"></script>

  <!-- firebaseUI -->
  <script src="https://cdn.firebase.com/libs/firebaseui/4.0.0/firebaseui.js"></script>
  <link
    type="text/css"
    rel="stylesheet"
    href="https://cdn.firebase.com/libs/firebaseui/4.0.0/firebaseui.css"
  />

  <script>
    // Your web app's Firebase configuration
    var firebaseConfig = {
      apiKey: "AIzaSyBtnE9XZR_tYckh5dYlwKbFdG3Nqs7y6JI",
      authDomain: "example123-6edfb.firebaseapp.com",
      databaseURL: "https://example123-6edfb.firebaseio.com",
      projectId: "example123-6edfb",
      storageBucket: "",
      messagingSenderId: "113254883849",
      appId: "1:113254883849:web:2e6706cd75b6bbd9"
    };

    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);

    // FirebaseUI config.
    var uiConfig = {
      signInSuccessUrl: "algo.html",
      signInOptions: [
        // Leave the lines as is for the providers you want to offer your users.
        firebase.auth.GoogleAuthProvider.PROVIDER_ID,
        firebase.auth.FacebookAuthProvider.PROVIDER_ID,
        firebase.auth.TwitterAuthProvider.PROVIDER_ID,
        firebase.auth.GithubAuthProvider.PROVIDER_ID,
        firebase.auth.EmailAuthProvider.PROVIDER_ID,
        firebase.auth.PhoneAuthProvider.PROVIDER_ID
      ],
      // tosUrl and privacyPolicyUrl accept either url string or a callback
      // function.
      // Terms of service url/callback.
      tosUrl: "<your-tos-url>",
      // Privacy policy url/callback.
      privacyPolicyUrl: function() {
        window.location.assign("<your-privacy-policy-url>");
      }
    };

    // Initialize the FirebaseUI Widget using Firebase.
    var ui = new firebaseui.auth.AuthUI(firebase.auth());
    // The start method will wait until the DOM is loaded.
    ui.start("#firebaseui-auth-container", uiConfig);
  </script>

但是访问页面时出现此错误

but i'm getting this error when i access the page

(索引):49未捕获的TypeError:无法读取未定义的属性"GoogleAuthProvider"在(index):49

(index):49 Uncaught TypeError: Cannot read property 'GoogleAuthProvider' of undefined at (index):49

有什么想法吗?

推荐答案

您缺少 auth 脚本文件

将其添加到您加载Firebase的位置:

add this where you are loading firebase:

 <!-- firebase -->
  <script src="https://www.gstatic.com/firebasejs/6.2.4/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/6.2.4/firebase-auth.js"></script>
  <!-- firebaseUI -->
  <script src="https://cdn.firebase.com/libs/firebaseui/4.0.0/firebaseui.js"></script>

如果您需要更多信息,请在此处

If you need more information, check the docs here

这篇关于解决方法:无法读取未定义的属性"GoogleAuthProvider"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 06:13