Cannot write to firebase database

Viewed 73

I'm trying to develop a website and now trying to configure sign up page. But after tons of modification, I can't write a new data to firebase database. Once, I could write to my database for a while but now I can't. I never modified my code after that. Here's my code and please let me know what is the problem. I appreciate every comments!! (I cannot catch any errors from console and set my rules to true for both write and read)

firebaseEmailAuth = firebase.auth();
firebaseDatabase = firebase.database();

var isAdduser = false;

$(document).ready(function(){

    $(document).on('click','.join',function(){


        var email = $('#inputEmail').val();
        var password = $('#inputPassword').val();
        name = $('#inputEmail').val();

        isAdduser = true;

        firebaseEmailAuth.createUserWithEmailAndPassword(email, password).catch(function(error) {

            var errorCode = error.code;
            var errorMessage = error.message;

            if (errorCode === 'auth/wrong-password') {
                alert('Wrong password.');
            } else {
                alert(errorMessage);
            }
            console.log(error);
            isAdduser = false ;

        });

    });});


function initApp() {

    firebase.auth().onAuthStateChanged(function(user) {

        if (user && isAdduser ) {

            var ref = firebaseDatabase.ref("users/"+ user.uid); 

            var name = $('#inputEmail').val();

            var obj = {name: name};

            ref.set(obj).then(success => {
                    console.log('success',success);
                },
                error => {
                    console.log('error',error);
                }
            );


            alert("You have successfully signed up!!");

            window.location.href = 'index.html';

        } else {}});}

window.onload = function() {
    initApp();
};

Rule settings:

rule settings

0 Answers
Related