2016-07-22 269 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规则使用经验。