Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ParseException: Invalid session token error

I did a simple sign up user interface just to check parse but for some reason every time i try to register a user it gives me this error

this is the code:

final ProgressDialog dlg = new ProgressDialog(this);
    dlg.setTitle("Please wait.");
    dlg.setMessage("Signing up.  Please wait.");
    dlg.show();

    String username_str = username.getText().toString();
    String password_str = password.getText().toString();
    String re_password_str = re_password.getText().toString();
    String email_str = email.getText().toString();
    String phone_str = phone.getText().toString();

    if(!re_password_str.equals(password_str)){
        dlg.dismiss();
        Toast.makeText(this,"Passwords does not match!!",Toast.LENGTH_SHORT).show();
        password.setText("");
        re_password.setText("");
    }else if(email_str.isEmpty()|| phone_str.isEmpty()){
        dlg.dismiss();
        Toast.makeText(this,"email or phone cannot be empty!!",Toast.LENGTH_SHORT).show();

    }else {
        ParseUser new_user = new ParseUser();
        new_user.setUsername(username_str);
        new_user.setPassword(password_str);
        new_user.setEmail(email_str);
        new_user.put("phone", phone_str);
        new_user.signUpInBackground(new SignUpCallback() {
            @Override
            public void done(ParseException e) {
                dlg.dismiss();
                if(e == null){
                    Intent i = new Intent(SignupActivity.this,MainActivity.class);
                    startActivity(i);
                }else{
                    Log.d("signup error", e.toString());
                    Toast.makeText(SignupActivity.this,e.toString(),Toast.LENGTH_SHORT).show();
                }
            }
        });

I've already spent 2 days in finding the problem but without any success....

like image 946
kitsuneFox Avatar asked Apr 01 '15 08:04

kitsuneFox


2 Answers

I have deleted manually some data from the Parse Database. After that I was having this error when I was trying to save a new user in background:

com.parse.ParseRequest$ParseRequestException: invalid session token

My solution was to uninstall the apk and install it again. It solved the session problem for me.

Important: I did this in the Debug Database, so uninstalling a Debug App and install it again was fine.

like image 143
Fernando Cardenas Avatar answered Sep 20 '22 19:09

Fernando Cardenas


You might not have logged out from your previous session. Make sure you have a log out logic. Also check if any of your users have logged in before signing in or signing up another user.

The belog code might help,

    var currentUser = Parse.User.current();
                if (currentUser) {
                    // do stuff with the user
                    Parse.User.logOut();
                } 

Also don't forget to add e.preventDefault(); in your sign up function.

This is how I had my signUp function..

$('.form-signup').on('submit', function(e) {

        var currentUser = Parse.User.current();
                if (currentUser) {
                    // do stuff with the user
                    Parse.User.logOut();
                } 

        e.preventDefault();
        var user = new Parse.User();

        var username = $('#username').val();
        var password = $('#password').val();
        var email = $('#email').val();

        user.set("username", username);
        user.set("password", password);
        user.set("email", email);

        user.signUp(null, {
            success: function(user) {
                //signup successfull
                alert("user created..!! User name: "+ username);
                window.location = "login.html";
            },
            error: function(user, error) {
                // Show the error message somewhere and let the user try again.
                console.log("Error: " + error.code + " " + error.message);
                //alert("User not created..!! " + error.message);
                $("H5").html("User not created..!! " +error.message);
            }
        });
});
like image 22
sudheeshcm Avatar answered Sep 17 '22 19:09

sudheeshcm