2016-07-22 263 views
0

不確定爲何此代碼未運行。從Firebase複製了所有必需的片段,並且我的按鈕正在觸發。任何想法可能會出錯? Github讓我在這裏寫更多東西。Firebase身份驗證

謝謝!

<head> 
    <meta charset=utf-8 /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>Auth</title> 
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase.js"></script> 
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-app.js"></script> 
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-auth.js"></script> 
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-database.js"></script> 
</head> 

<body> 

    <button onclick="googleAuth()">SIGN UP</button> 

<script> 

    var provider = new firebase.auth.GoogleAuthProvider(); 

    var googleAuth = function() { 
    console.log(firebase); 
    firebase.auth().signInWithPopup(provider).then(function(result) { 
     // This gives you a Google Access Token. You can use it to access the Google API. 
     var token = result.credential.accessToken; 
     // The signed-in user info. 
     var user = result.user; 
     // ... 
    }).catch(function(error) { 
     // Handle Errors here. 
     var errorCode = error.code; 
     var errorMessage = error.message; 
     // The email of the user's account used. 
     var email = error.email; 
     // The firebase.auth.AuthCredential type that was used. 
     var credential = error.credential; 
     // ... 
    }); 
}; 


</script> 








    <script> 
    // Initialize Firebase 
    var config = { 
     apiKey: "AIzaSyBeJIaAAD5-vK0kBDTRH6Y6_1ByVE3erJY", 
     authDomain: "fir-chat-d28be.firebaseapp.com", 
     databaseURL: "https://fir-chat-d28be.firebaseio.com", 
     storageBucket: "fir-chat-d28be.appspot.com", 
    }; 
    firebase.initializeApp(config); 
    </script> 

</body> 

回答

2

您必須按照日誌說明:

The current domain is not authorized for OAuth operations. This will prevent signInWithPopup, signInWithRedirect, linkWithPopup and linkWithRedirect from working. Add your domain to the OAuth redirect domains list in the Firebase console -> Auth section -> Sign in method tab. 

看看它是怎麼說的signInWithPopup不會沒有火力地堡控制檯添加域工作

+0

我在瀏覽器中查看html文件,因此我無法在firebase中添加域。我也沒有在控制檯中得到任何錯誤。 – maxwellgover

+0

瀏覽器中的域名是什麼? – Angelo

+0

file:/// C:/Users/MGover/Desktop/index.html – maxwellgover

0

您的代碼看起來不錯,但如果你運行一個HTML文件,你會得到類似的錯誤「此操作不會在環境中支持該應用程序運行上。」位置。協議「必須是http或https」。

我建議你利用Firebase Hosting功能。您可以輕鬆部署和託管您的應用程序的靜態資產,如HTML,CSS,JavaScript等。此外,它是免費的。

0

以我的經驗(只是建議),不要使用像谷歌或臉書提供商的firebase身份驗證。使用電子郵件和密碼認證,以提高安全性。你可以使用FirebaseUi,簡單易懂,如果你喜歡,你可以複製粘貼。如果您使用Google身份驗證,那麼每個擁有Google帳戶的用戶都可以訪問您的應用,讀取,寫入,刪除和更新。除非您有更好的Firebase規則使用經驗。