Haven't perfect understanding with Firebase-Database and Firebase-authentication

62
January 11, 2019, at 7:30 PM

In hear I'm supposed to register users from my web app. But after one user registration, the second user always removes current user details and come under the previous uid.

Here is my code.

<script>
      // Already Initialized Firebase

      var text = document.getElementById('name');
      var email = document.getElementById('email');
      var password = document.getElementById('password');
      var button = document.getElementById('button');

      var profilePic = document.getElementById('profilePic');


      function registerUser(){

      var Name = text.value;
      var Email = email.value;
      var Password = password.value;
      var Image = profilePic.files[0];
      window.alert(Name)
      firebase.auth().createUserWithEmailAndPassword(Email, Password).catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
      // ...
    });
      var user = firebase.auth().currentUser;
      var uid = user.uid;
      var dbRefUid = firebase.database().ref().child('Web App').child('Users');
      dbRefUid.set(uid);
      var dbRefName = firebase.database().ref().child('Web App').child('Users').child(uid).child('Name');
      var dbRefEmail = firebase.database().ref().child('Web App').child('Users').child(uid).child('Email');
      var dbRefPassword = firebase.database().ref().child('Web App').child('Users').child(uid).child('Password');
      var dbRefProfilepicUrl = firebase.database().ref().child('Web App').child('Users').child(uid).child('Profilepicture URL');

      dbRefName.set(Name);
      dbRefEmail.set(Email);
      dbRefPassword.set(Password);

      var imageRoot = firebase.storage().ref('users/' + "profile");
      imageRoot.put(Image);

      var uploadTask = imageRoot.put(Image);
    // Register three observers:
    // 1. 'state_changed' observer, called any time the state changes
    // 2. Error observer, called on failure
    // 3. Completion observer, called on successful completion
    uploadTask.on('state_changed', function(snapshot){
      // Observe state change events such as progress, pause, and resume
      // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
      var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
      console.log('Upload is ' + progress + '% done');
      switch (snapshot.state) {
        case firebase.storage.TaskState.PAUSED: // or 'paused'
          console.log('Upload is paused');
          break;
        case firebase.storage.TaskState.RUNNING: // or 'running'
          console.log('Upload is running');
          break;
      }
    }, function(error) {
      // Handle unsuccessful uploads
    }, function() {
      // Handle successful uploads on complete
      // For instance, get the download URL: https://firebasestorage.googleapis.com/...
      uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
        dbRefProfilepicUrl.set(downloadURL);
        console.log('File available at', downloadURL);
      });
    });
      firebase.auth().signOut().then(function() {
        window.alert("Sign Out")
      // Sign-out successful.
    }).catch(function(error) {
      // An error happened.
    });
      }
    </script>

My requirement is to register different users with unique uid via firebase database and firebase authentication feature. Both places should be same uniqe uid's. Everything is working. But not the way I wish.

READ ALSO
Android APK not installing in device

Android APK not installing in device

I have created Same project as two WorkSpace in my systemex: AppSampleHindi and AppSampleEnglish,

46
Android: Testing an ExecutorService on the main thread

Android: Testing an ExecutorService on the main thread

I'm having a ViewModel with a code that is running inside the execute block (inside a Runnable)It all works fine, except that I can't successfully make the code run in the main thread when unit testing it (even debugging it, I can see the code inside...

26
assigning a unique id for button [on hold]

assigning a unique id for button [on hold]

suppose there exist a form and has two button ,i want one button to get disabled until all parameter is filled by user while other Enabled,for users to navigate to back panelIs there exist a function to assign unique id to buttons?

48