2016-07-22 11 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

あなたはログの指示に従わなければならない:それはsignInWithPopupがFirebaseコンソールで追加したドメインなしでは動作しませんと言う方法を参照してください

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. 

+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

私の経験では(ちょうど助言のために)、googleやfacebookのようなプロバイダでfirebase authを使わないでください。より良いセキュリティのために電子メールとパスワード認証を使用してください。 FirebaseUi、verryを理解しやすいように使うことができます。また、好きなだけコピーして貼り付けることもできます。 Google認証を使用すると、Googleアカウントを持っているすべてのユーザーがあなたのアプリにアクセスし、読み取り、書き込み、削除、更新することができます。ただし、Firebase Rulesの方が優れています。