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

127
Views
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
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!