Ashutosh Maheshwari Ashutosh Maheshwari - 28 days ago 4x
Javascript Question

How to know if data on firebase is saved before moving to next webpage?

I am making a signup page. Users enter their name, username, email, password for sign up. After they clicked sign up they are redirected to new page, but before moving that I want to make sure their entered data is saved in firebase database. How to make sure data is saved before moving on to next webpage?

function SignUP(){
const emailID = _email.value;
const pass = _password.value;
const auth = firebase.auth();
const promise = auth.createUserWithEmailAndPassword(emailID, pass);
promise.catch(e => console.log(e.message));
function writeUserData(user, fname, lname) {
var myuser = {
username: name,
firstName: fname,
lastName: lname
firebase.auth().onAuthStateChanged(firebaseUser => {
const fName = _firstName.value;
const lName = _lastName.value;
const uName = _username.value;
writeUserData(uName, fName, lName);
console.log('not logged in');


Wire up a .then to the push:

    //data is saved