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
    • 388
    Answer it
    1. //Signup
    2. const signupForm = document.querySelector("#signup-form");
    3. signupForm.addEventListener("submit", e => {
    4. e.preventDefault();
    5. // feel free to change the object keys to match your data model
    6.  
    7. db.ref("users/").push({
    8. chosenPlan: signupForm["plan"].value,
    9. investment_capital: signupForm["invest-capital"].value,
    10. roi_model: signupForm["ROI-modl"].value,
    11. investment_funding_medium: signupForm["depost-id"].value,
    12. firstname: signupForm["first-name"].value,
    13. othernames: signupForm["other-names"].value,
    14. country: signupForm["country"].value,
    15. city: signupForm["city"].value,
    16. email: signupForm["email"].value,
    17. phone: signupForm["phone"].value,
    18. password: signupForm["password"].value,
    19. retypepassword: signupForm["retypepassword"].value,
    20. referreremail: signupForm["referreremail"].value
    21. });
    22.  
    23.  
    24. //Get Users Info
    25. const email = signupForm["email"].value;
    26. const password = signupForm["password"].value;
    27.  
    28. // sign up the user
    29. auth
    30. .createUserWithEmailAndPassword(email, password)
    31. .then(cred => {
    32. //Hide Alert
    33. setTimeout(() => {
    34. document.getElementById("tx").innerHTML =
    35. " Your registration was successful please proceed to the login page.";
    36. }, 3000);
    37. window.location.replace("/admin/admin-html/Dashboard.html");
    38. })
    39. .then(() => {
    40. const uid = cred.user.uid; // you have uid
    41. cred.user.getIdToken().then(
    42. token => {
    43. // do anything with token
    44. console.log(token);
    45. },
    46. err => {
    47. console.log(err.message);
    48. }
    49. );
    50. });
    51.  
    52. //reset form
    53. signupForm.reset();
    54. });
    55.  
    56. auth.onAuthStateChanged(user => {
    57. if (user) {
    58. console.log("user logged in: ", user.email);
    59. } else {
    60. console.log("user logged out");
    61. }
    62. });
    63.  
    64. db.ref("users/").on("value", function (snapshot) {
    65. console.log(snapshot.val());
    66. });
    67.  
    68.  
    69.  

    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
Reset Password
Fill out the form below and reset your password: