2016-06-25 27 views
2

ユーザーがサインインした後に別のウェブページにリダイレクトするにはどうすればよいですか?ユーザーがFirebase認証でサインインした後にリダイレクトする方法は?

現在、ユーザーがログインすると、データは取得されますが、ユーザーは別のWebサイトにリダイレクトされません。

私は、私が使用する必要があります知っている「getRedirectResult」、誰かがそれを使用する方法私を見るとどのようにそれを取得したユーザーデータを保持し、別のウェブページにユーザーをリダイレクトすることができます。

私のjavascriptの仕事:

function toggleSignIn() { 
    if (!firebase.auth().currentUser) { 
    // [START createprovider] 
    var provider = new firebase.auth.GoogleAuthProvider(); 
    // [END createprovider] 
    // [START addscopes] 
    provider.addScope('https://www.googleapis.com/auth/plus.login'); 
    // [END addscopes] 
    // [START signin] 
    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; 
     // [START_EXCLUDE] 
     document.getElementById('quickstart-oauthtoken').textContent = token; 
     // [END_EXCLUDE] 
    }).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; 
     // [START_EXCLUDE] 
     if (errorCode === 'auth/account-exists-with-different-credential') { 
     alert("You have already signed up with a different auth provider for that email."); 
     // If you are using multiple auth providers on your app you should handle linking 
     // the user's accounts here. 
     } 
    else if (errorCode === 'auth/auth-domain-config-required') { 
    alert("An auth domain configuration is required"); 
     } 
     else if (errorCode === 'auth/cancelled-popup-request') { 
      alert("Popup Google sign in was canceled"); 
     } 
     else if (errorCode === 'auth/operation-not-allowed') { 
      alert("Operation is not allowed"); 
     } 
     else if (errorCode === 'auth/operation-not-supported-in-this-environment') { 
      alert("Operation is not supported in this environment"); 
     } 
     else if (errorCode === 'auth/popup-blocked') { 
      alert("Sign in popup got blocked"); 
     } 
     else if (errorCode === 'auth/popup-closed-by-user') { 
      alert("Google sign in popup got cancelled"); 
     } 
     else if (errorCode === 'auth/unauthorized-domain') { 
      alert("Unauthorized domain"); 
     } 
     else { 
     console.error(error); 
     } 
     // [END_EXCLUDE] 
    }); 
    // [END signin] 
    } else { 
    // [START signout] 
    firebase.auth().signOut(); 
    // [END signout] 
    } 
    // [START_EXCLUDE] 
    document.getElementById('quickstart-sign-ing').disabled = false; 
    // [END_EXCLUDE] 
} 
+0

あなたはきちんと英語を書いていないために謝罪する必要はありません。あなたは、しかし、あなたはすでに試したものを私たちに示し、あるいは少なくとも、あなたが理解していなかった被写体に読んでいるドキュメントに私たちを指すことができます! – Zimano

+0

このjavascriptコードで "getRedirectResult"を実装する方法を知りたいです。そして、私はまた、HTML –

答えて

1

あなたは単一ページのスタイルのアプリケーションを構築している場合、あなたはおそらくリダイレ​​クトする必要はありません。代わりに、ユーザーのログイン時にアプリケーションの状態を変更するだけです。ただし、URLを変更する場合は、成功コールバックでJavaScriptを使用してウィンドウの場所を設定するだけです。たとえば:新しいページにあなたにも認証状態をリッスンする必要があること

window.location = '/logged_in.html' 

注:ドン」の場合ウェブ上で一般Firebaseアプリケーションで

firebase.auth().onAuthStateChanged(function(currentUser) { 
    if (currentUser) { 
    // the user is logged in, you can bootstrap functionality now 
    } 
}); 

は、より良い仕事しますtあなたのアプリは、状態遷移の間にハードページの読み込みが必要な構造になっています。余分なページを読み込まなくても、JavaScriptを使用してすべてを管理できます。

+0

を使用していますあなたは私のjavascriptのコード –

+0

リダイレクト作品でこれを実装する方法を知っていますが、それはちょっとムルは、あなたがあなたの星座のように異なる起源にサインインしようとしている –

+0

取得したユーザーのデータを維持しませんページ? Web用のFirebase認証は、単一のホスト原点のみです。サインイン後に別のWebページにリダイレクトすると、サインインしたユーザーは利用できなくなります。 – bojeil

関連する問題