2016-06-25 11 views
2

사용자가 로그인 한 후에 다른 웹 페이지로 리디렉션 할 수 있습니까?사용자가 Firebase 인증을 사용하여 로그인 한 후 리디렉션하는 방법은 무엇입니까?

현재 사용자가 로그인하면 데이터가 검색되지만 사용자를 다른 웹 사이트로 리디렉션하지 않습니다.

'getRedirectResult'를 사용해야하지만 다른 사람이 내 웹 페이지를 사용하는 방법과 검색된 사용자 데이터를 유지 관리하는 방식을 사용자에게 보여줄 수 있는지 알고 있습니다.

내 자바 스크립트 작업 :

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

이 자바 스크립트 코드에서 "getRedirectResult"를 구현하는 방법을 알고 싶습니다. 그리고 HTML도 사용하고 있습니다 –

답변

1

단일 페이지 스타일의 응용 프로그램을 작성하는 경우, 당신은 가능성이 리디렉션 할 필요가 없습니다. 대신 사용자가 로그인 할 때 응용 프로그램 상태를 변경하면됩니다. 그러나 URL을 변경하려면 성공 콜백에서 JavaScript를 사용하여 창 위치를 간단히 설정할 수 있습니다. 예를 들어 새 페이지에

window.location = '/logged_in.html' 

주 당신은뿐만 아니라 인증 상태를 수신해야합니다 일반적으로 중포 기지 응용 프로그램에서

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

을 웹이 더 잘 작동에 만약 당신이 돈 ' t 귀하의 앱이 상태 전환 사이에 하드 페이지를로드하도록 구성하십시오. 추가 페이지로드가 필요없이 JavaScript를 사용하여 모든 것을 관리 할 수 ​​있어야합니다.

+0

내 자바 스크립트 코드 –

+0

에서이를 구현하는 방법을 알고 있습니까? 리디렉션은 작동하지만 검색된 사용자 데이터를 유지 관리하지 않습니다. –

+0

안녕하세요, Mulu 님, 로그인 할 때 다른 출처로 로그인을 시도하고 있습니까? 페이지? 웹용 Firebase 인증은 단일 호스트에서만 가능합니다. 로그인 한 후 다른 웹 페이지로 리디렉션하면 로그인 한 사용자를 사용할 수 없습니다. – bojeil