Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda