1

我使用Windows 8.我想用this guide.构建一个应用程序。在第7步,我更改main.js文件。我的文件内容如下:Firebase - 网络聊天应用程序登录按钮不起作用

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> 

我在cmd终端上运行“firebase serve”命令。我打开本地主机:/ 5000and的页面如下:

enter image description here

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

回答

1

低于初始化适用于我。

{ 

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

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

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

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

+0

我改变firebase.json在网上开始,但结果并没有改变。新的含量低于:'“托管”:{ “公”:“网络启动”, “重写“:[ { ”source“:”**“, ”destination“:”/index.html“ } ] }'' – zumma