2017-02-05 7 views
0

マイapp.jsは次のようになります。私は私のページをロードする際Googleの認証無限ループ

// Initialize Firebase 
    const config = { 
     apiKey: //... 
     authDomain: //... 
     databaseURL: //... 
     storageBucket://... 
     messagingSenderId: //... 
    }; 
    firebase.initializeApp(config); 

}()); 

    function.googleSignin(){ 
     var provider = new firebase.auth.GoogleAuthProvider(); 
     firebase.auth().signInWithRedirect(provider); 
    } 

    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; 
    // ... 
}); 

しかし、今、それが自動的に(今のところ、私は彼らがにリダイレクトされるようにしたいサインインGoogleにリダイレクトしますボタンをクリックするとログインできます)。もっと重要なことは、これは無限ループでこれを行います。既にログインした後に私をログインページにリダイレクトします。

ボタンをクリックしたときだけリダイレクトする必要があるのは何ですか?その後、自動的にGoogleログインにリダイレクトされませんか?

============================================== ============================= 私はWeb開発に非常に新しいですし、完全に私の中で、Googleの記号を統合する方法として失われていますFirebase上でホストされているアプリです。私は、Googleのサインインボタンを持つポップアップを作成しました。

   <div id="id01" class="modal"> 
       <form class="modal-content animate" action="action_page.php"> 
        <div class="imgcontainer"> 
         <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span> 
         </div> 
         <div class="loginMsg"> 
          <p>hi there!</p> 
          <p>log in to post and comment on ride share</p> 
         </div> 
         <button class="loginBtn loginBtn--facebook">connect with facebook</button> 
         <button class="loginBtn loginBtn--google">connect with google  </button> 
       </form> 
      </div> 

私はFirebase instructionsを理解しようとしていますが、私は迷っています。私のコードのどこでこれらのステップを実行しますか? 「VARプロバイダ=新しいfirebase.auth.GoogleAuthProviderを();」たとえば、私は含まれません私のindex.htmlページのスクリプトで? app.jsでもちろん、このログイン機能にリダイレクトするためのボタンが必要なので、どうすればいいですか?

答えて

1

あなたは同じボタンのクリックコールバックでsignInWithRedirectとgetRedirectResultを呼び出すことはできません。

通常は、ここで何ができるかです:

クリックハンドラであなたのボタンについては、次の手順を実行します。あなたの関数の集合の外

function.googleSignin(){ 
    var provider = new firebase.auth.GoogleAuthProvider(); 
    firebase.auth().signInWithRedirect(provider); 
} 

リスナーをリダイレクト:

firebase.auth().getRedirectResult().then(function(result) { 
    if (result.user) { 
    // User just signed in. you can get the result.credential. 
    // Update your UI, hide the sign in button. 
    } else if (firebase.auth().currentUser) { 
    // User already signed in. 
    // Update your UI, hide the sign in button. 
    } else { 
    // No user signed in, update your UI, show the sign in button. 
    } 
});