Firebase Web身份验证无效

问题描述 投票:0回答:1

我试图在我的网站中添加Firebase身份验证。我试过这段代码:

<!DOCTYPE html>
<html>
    <head>
    <meta charset="UTF-8"> 
    <title>
        Sample FirebaseUI App
    </title>
    <!-- ******************************************************************************************* * TODO(DEVELOPER): Paste the initialization snippet from: * Firebase Console > Overview > Add Firebase to your web app. * ***************************************************************************************** -->
    <script type="text/javascript">
        // Initialize Firebase
  var config = {
    apiKey: "AIzaSyB7cfgbxS4UgkGwsHyFgYwa6Ir7eRTWHM0",
    authDomain: "web-teachinger.firebaseapp.com",
    databaseURL: "https://web-teachinger.firebaseio.com",
    projectId: "web-teachinger",
    storageBucket: "",
    messagingSenderId: "1070392376591"
  };
  firebase.initializeApp(config);
    </script>
    <script src="https://cdn.firebase.com/libs/firebaseui/2.5.1/firebaseui.js"></script>
    <link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/2.5.1/firebaseui.css" />
    <script type="text/javascript">
  firebase.initializeApp(config);
        // FirebaseUI config. 
        var uiConfig = { 
        signInSuccessUrl: 'success.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 
], 
// Terms of service url. 
tosUrl: 'TOS.php' }; 
// 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>
  </head> 
  <body>
     <!-- The surrounding HTML is left untouched by FirebaseUI. Your app may use that space for branding, controls and other customizations.-->
     <h1>
         Welcome to My Awesome App
     </h1>
  <div id="firebaseui-auth-container">
  </div>
 </body>
</html>

但是,当我访问Localhost时,它只显示“欢迎使用我的真棒应用程序”,并且没有使用身份验证提供程序,也没有看到容器。请帮助注意:您也可以在Localhost中测试此代码。

html html5 firebase firebase-authentication firebaseui
1个回答
0
投票

您在控制台中收到以下错误:Uncaught ReferenceError: firebase is not defined

您不包括Firebase JS CDN:<script src="https://www.gstatic.com/firebasejs/4.8.1/firebase.js"></script>

© www.soinside.com 2019 - 2024. All rights reserved.