TEL:400-8793-956
当前位置:程序、服务器

如何在NoSQL中从Firebase读取数据?

提问者: 近期获赞: 浏览人数: 发布时间:2021-02-03 14:58:17

 问://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());
});
我是Firebase的新手,并且想读取当前登录用户的数据。
 
我已经尝试过,但最终还是从集合中获取了全部数据。
 
 
答: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());
});
上一篇: 任何人都可以解释该程序的输出
下一篇: 如何解决我的网页设计上的UI UX问题