Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
¿Por qué setPersistence no funciona en Firebase?

Estoy tratando de mantener a los usuarios conectados independientemente de la página en la que se encuentren hasta que decidan cerrar la sesión. Estoy tratando de hacer esto inicializando la configuración de firebase en cada página para tener un tipo de persistencia de browserLocalPersistence. Desafortunadamente, el usuario actualmente no permanece conectado después de que se cambia/recarga la página. ¿Dónde me estoy equivocando? No se están produciendo errores.

 import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.6.7/firebase-app.js' // Add Firebase products that you want to use import { initializeAuth, signInWithEmailAndPassword, signOut, setPersistence, browserSessionPersistence, browserLocalPersistence, indexedDBLocalPersistence } from 'https://www.gstatic.com/firebasejs/9.6.7/firebase-auth.js' const firebaseConfig = { apiKey: "xxx", authDomain: "xxx.firebaseapp.com", databaseURL: "https://xxx.firebaseio.com", projectId: "xxx", storageBucket: "xxx.appspot.com", messagingSenderId: "xxx", appId: "xxx", measurementId: "xxx", persistence: browserLocalPersistence }; // Initialize Firebase const app = initializeApp(firebaseConfig); const auth = initializeAuth(app); console.log(app, auth); auth.onAuthStateChanged(user => { if (user) { console.log('User logged in: ', user); const navRight = document.getElementById('navRight'); navRight.innerHTML = `<a id="logout" href=".">LOGOUT</a><a href="../about/">ABOUT</a>`; // Logout const logout = document.getElementById("logout"); logout.addEventListener('click', (e) => { e.preventDefault(); console.log('User logged out'); signOut(auth).then(); }); } else { console.log('User not logged in'); } }); const loginForm = document.querySelector('#login-form'); const loginButton = document.getElementById("login-button"); var identification = ""; var password = ""; // Login loginForm.addEventListener('submit', (e) => { console.log(1); e.preventDefault(); var identification = loginForm['identification'].value; var password = loginForm['password'].value; var loggedIn = false; console.log(2); setPersistence(auth, browserLocalPersistence); setPersistence(auth, browserLocalPersistence) .then(() => { // Existing and future Auth states are now persisted in the current // session only. Closing the window would clear any existing state even // if a user forgets to sign out. // ... // New sign-in will be persisted with session persistence. return signInWithEmailAndPassword(auth, identification, password); }) .catch((error) => { // Handle Errors here. const errorCode = error.code; const errorMessage = error.message; console.log(errorCode); console.log(errorMessage); });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!