Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Read Data from Firebase in NoSQL?

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 339
    Answer it
    //Signup
    const signupForm = document.querySelector("#signup-form");
    signupForm.addEventListener("submit", e => {
      e.preventDefault();
      // feel free to change the object keys to match your data model
    
      db.ref("users/").push({
        chosenPlan: signupForm["plan"].value,
        investment_capital: signupForm["invest-capital"].value,
        roi_model: signupForm["ROI-modl"].value,
        investment_funding_medium: signupForm["depost-id"].value,
        firstname: signupForm["first-name"].value,
        othernames: signupForm["other-names"].value,
        country: signupForm["country"].value,
        city: signupForm["city"].value,
        email: signupForm["email"].value,
        phone: signupForm["phone"].value,
        password: signupForm["password"].value,
        retypepassword: signupForm["retypepassword"].value,
        referreremail: signupForm["referreremail"].value
      });
    
    
      
      
      //Get Users Info
      const email = signupForm["email"].value;
      const password = signupForm["password"].value;
    
      // sign up the user
      auth
        .createUserWithEmailAndPassword(email, password)
        .then(cred => {
          //Hide Alert
          setTimeout(() => {
            document.getElementById("tx").innerHTML =
              " Your registration was successful please proceed to the login page.";
          }, 3000);
          window.location.replace("/admin/admin-html/Dashboard.html");
        })
        .then(() => {
          const uid = cred.user.uid; // you have uid
          cred.user.getIdToken().then(
            token => {
              // do anything with token
              console.log(token);
            },
            err => {
              console.log(err.message);
            }
          );
        });
    
      //reset form
      signupForm.reset();
    });
    
    auth.onAuthStateChanged(user => {
      if (user) {
        console.log("user logged in: ", user.email);
      } else {
        console.log("user logged out");
      }
    });
    
    db.ref("users/").on("value", function (snapshot) {
      console.log(snapshot.val());
    });
    
    
    

    I'm new to firebase and would like to read data of a currently logged in user.

    i've tried but I end up getting the whole data from the collection.

 1 Answer(s)

  • After Login, you will get a User uid, by this id you can get logged in user detail from firebase realtime database, here is the example :-

    db.ref("users/"+uid).on("value", function (snapshot) {

    console.log(snapshot.val());
    });
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: