with usuario signinwithredirect signinwithemailandpassword sesion password integrar google correo cerrar auth javascript firebase firebase-authentication

javascript - usuario - signinwithemailandpassword firebase web



¿Cómo redirigir después de que un usuario inicia sesión con la autenticación de Firebase? (1)

¿Cómo puedo redireccionar a una página web diferente después de que el usuario se haya registrado?

Actualmente, cuando un usuario inicia sesión, los datos se recuperan, sin embargo, no redirige al usuario a un sitio web diferente.

Sé que debería usar ''getRedirectResult'', pero alguien puede mostrarme cómo usarlo y cómo redirige al usuario a una página web diferente, manteniendo los datos de usuario recuperados.

Mi trabajo de 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] }


Si está creando una aplicación de estilo de una sola página, probablemente no necesite redirigirla. En cambio, simplemente cambiaría el estado de su aplicación cuando el usuario inicia sesión. Sin embargo, si desea cambiar la URL, simplemente puede establecer la ubicación de la ventana mediante JavaScript en su exitosa devolución de llamada. Por ejemplo:

window.location = ''/logged_in.html''

Tenga en cuenta que en la nueva página también deberá escuchar el estado de autenticación:

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

En general, las aplicaciones de Firebase en la web funcionarán mejor si no se estructura su aplicación para que necesite cargas de páginas duras entre transiciones de estado. Todo puede e idealmente debe administrarse usando JavaScript sin requerir una carga de página adicional.