1
btnsubmit.addEventListener('click', e => {

        const task = txttask.value;
        const description = txtdescription.value;
        const date = txtdate.value;
        firebase.auth().onAuthStateChanged(firebaseUser => {
            if (firebaseUser) {
                console.log(firebaseUser.email)
                firebase.database().ref('uid/' + firebaseUser.uid + '/reminders/' + date).set({
                    task: task,
                    description: description,
                    date: date,
                });
                alert('Data Has Been Recorded');

            }
        });
        document.getElementById("input_form").reset();

so when I hit the submit button I get the alert but the data is not saved.

another example

      if (firebaseUser) {
        console.log(firebaseUser);
        return window.location.href = 'index.html';

      } else {
        if (email == '' && pass == '') {
          alert('Please Enter The Email and The Password!')
        } else if (pass == '') {
          alert('Please Enter The Password!')
        } else if (email == '') {
          alert('Please Enter The Email')
        }
        else {
          if (firebaseUser) {
            console.log(firebaseUser);
            return window.location.href = 'index.html';
          } else {
            alert('Something went wrong')

          }
        }
        console.log("not loged in");

      }
    });

Here the website shows the alert that something went wrong and when I clear it I'm logged in. I added extra if to again check if the user exists just in the case. but it still does that, so I'm confused as to what am I doing wrong in both scenarios.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
knvgpt
  • 17
  • 3
  • Does this answer your question? [How to return value from an asynchronous callback function?](https://stackoverflow.com/questions/6847697/how-to-return-value-from-an-asynchronous-callback-function) – Andy Ray May 16 '21 at 17:34
  • Async/callback functions don't execute top top bottom, the async function executes long after the rest of your parent function has finished running. This is the most common type of JS question on StackOverflow. – Andy Ray May 16 '21 at 17:36

0 Answers0