Monaca.cloud not working



  • Hello,

    I am writing a polling app but I can’t seem to get monaca.cloud.User.register or .validate or.login or anything to work. The parent function fires but nothing happens inside monaca.cloud functions. Here is my app.js:

    $(function() {
        $("#register").click(register);
        $("#registerUser").click(registerUser);
        $("#login").click(login);
    });
    
    function register(){
        $.mobile.changePage("#registration");
    }
    
    function login() {
     var username = $("#username").val();
     var password = $("#password").val();
     console.log('login');
        monaca.cloud.User.login(username, password)
        .done(function(result){
        $.mobile.changePage("#home");
        }).fail(function(err){
        console.log("Err#" + err.code +": " + err.message);
        });
    }
    function registerUser() {
        var name = $("#registerUsername").val();
        var password1 = $("#registerPassword").val();
        var password2 = $("#confirmPassword").val();
        if(password1 != password2) {
            $("#registerError").css("display", "block");
        }
        else {
            monaca.cloud.User.validate(name).done(function(result)
                {
                    console.log('Registered.');
                  monaca.cloud.User.register(name, password1)
                        .done(function(result)
                        {
                           console.log("Welcome, " + result.user._username);
                           console.log("You are " + result.user.age + " years old.");
                        }
                        )
                        .fail(function(err)
                        {
                           console.log("Err#" + err.code +": " + err.message);
                        });
                $.mobile.changePage("#home");
                       
                }).fail(function(err)
                {
                   console.log("Err#" + err.code +": " + err.message);
                   $("#registerError").text("Username has already been taken.");
                    $("#registerError").css("display", "block");
                 });    
        }
    };
    

    Any help is much appreciated!


  • Monaca

    @kelifine There seem to be nothing wrong with your code. Did you receive any error? Please make sure you are setting up the Backend properly. If possible, can you show me your backend setting?


Log in to reply