//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)