Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
Firebase Real time data base isnt working

Here's my index.js file code

// Initialize Vars
// const auth=firebase.auth()
// const database=firebase.database()
import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";
const auth = getAuth(); 
//set up register function 
function register(){
    //Get Input fields 
    email= document.getElementById(email).value
    password = document.getElementById(password).value
}
//Continue with Auth
auth.createUserWithEmailAndPassword(email,password)
.then((result) => 
{
    var user=auth.currentUser
// add this user to firebase 
var database_ref=database.ref()


//Create user data 
var user_data={
    email: email,
    last_login:Date.now()
}
database_ref.child('users/'+user.uid).set(user_data)


    alert("User Created!")
 //if I screw up   
}).catch((err) => {
    var error_code = error_code
    var error_message= error_message
    alert(error_message)
});

if(validate_email(email) ==false ||validate_pass(password) ==false)
alert("Email or password isn't correct")
//dont run future code 
function validate_email(email){
expression= /^[^@]+@\w+(\.\w+)+\w$/.test(str);
if (expression.test(email) ==true){
    //Email is good 
    return true
}
else{
    //Email is not good
    return false
}
}
function validate_pass(password){
    //firebase only accepts passwords greater than 6 letters 
    if(password<6){
        return false
    }
    else{
        return true
    }
}

and here's my HTML file

 <script>
  // Import the functions you need from the SDKs you need
  import { initializeApp } from "firebase/app";
  import { getAnalytics } from "firebase/analytics";
  import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";
  // TODO: Add SDKs for Firebase products that you want to use
  // https://firebase.google.com/docs/web/setup#available-libraries
  
  // Your web app's Firebase configuration
  // For Firebase JS SDK v7.20.0 and later, measurementId is optional
  const firebaseConfig = {
  // Initialize Firebase
  const app = initializeApp(firebaseConfig);
  const analytics = getAnalytics(app);</script>
  <script src="js/index.js"></script>

Im sure I got everything correct so I don't understand why firebase won't add a user to the database. I even downloaded the Firebase Npm to see if that was necessary but even with that, it wasn't working. I think the auth is also correct so I don't understand the problem. In case anyone understands the problem please let me know.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda