Firebase - Web Chat App登录按钮不起作用

时间:2016-06-13 09:35:15

标签: firebase firebase-realtime-database firebase-authentication firebase-hosting

我使用的是Windows 8.我想使用this guide.构建一个应用程序。在第7步,我更改main.js文件。我的文件内容如下:

FriendlyChat.prototype.initFirebase = function() {
  this.auth = firebase.auth();
  this.database = firebase.database();
  this.storage = firebase.storage();
  this.auth.onAuthStateChanged(this.onAuthStateChanged.bind(this));
};


FriendlyChat.prototype.signIn = function(googleUser) {

   var provider = new firebase.auth.GoogleAuthProvider();
  this.auth.signInWithPopup(provider);
};

FriendlyChat.prototype.signOut = function() {
  this.auth.signOut();
};

FriendlyChat.prototype.onAuthStateChanged = function(user) {
if (user) { // User is signed in!
  var profilePicUrl = user.photoURL; // Only change these two lines!
  var userName = user.displayName;   // Only change these two lines!
  ....
}

FriendlyChat.prototype.checkSignedInWithMessage = function() {
  if (this.auth.currentUser) {
    return true;
  }
  ....

我使用firebase控制台创建一个项目。我点击了"将Firebase添加到您的网络应用中"然后单击该代码段。我将其粘贴到index.html文件。文件内容如下:

<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script>

<script>
  // Initialize Firebase
  var config = {
    apiKey: "AIzaSyAbtFJIZZxExBZec5XjsIE6p_TK4x-NDLE",
    authDomain: "xxx-65704.firebaseapp.com",
    databaseURL: "https://xxx-65704.firebaseio.com",
    storageBucket: "xxx-65704.appspot.com",
  };
  firebase.initializeApp(config);
</script>    
<script src="scripts/main.js"></script>    
</body>

我跑&#34; firebase服务&#34;命令在cmd终端上。我打开localhost:/ 5000,页面如下:

enter image description here

它不显示网络聊天。所以我打开we-start / index.html,点击&#34;用Google登录&#34;。但我无法登录。我不知道如何解决这个问题。我的错是什么?

2 个答案:

答案 0 :(得分:1)

以下初始化适用于我。

{

  "hosting": {
    "public": "./",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

答案 1 :(得分:0)

您的firebase.json很可能没有为文件所在的位置指定正确的目录。在你的情况下应该是:

{
  "hosting": {
    "public": "we-start",
    ...

有关所有属性的完整说明,请参阅reference section of the Firebase Hosting documentation