kitsuneFox
kitsuneFox

Reputation: 1271

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....

Upvotes: 9

Views: 27121

Answers (8)

Saurav Pratihar
Saurav Pratihar

Reputation: 31

It is due to data deletion from database but local storage still have that data. So you have to clear data from local storage.

Eg. For Javascript (browser):

window.localStorage.clear()

For React Native:

AsyncStorage.clear();

For android: Either clear cache or reinstall app

Upvotes: 3

Fernando Cardenas
Fernando Cardenas

Reputation: 1232

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.

Upvotes: 13

user1211030
user1211030

Reputation: 3050

If you encounter this problem in your web app, clear the local storage of all Parse data. On Chrome this is:

  1. Developer Tools (F12)
  2. Application
  3. Local Storage
  4. Choose Parse entries and press Delete key (or Backspace)

Upvotes: 0

Yes I think after signing up a user you might have deleted that row from the users class, so first, write this code in your Activity

if(ParseUser.getCurrentUser()!=null){
   Toast.makeText(this,"yes not null",Toast.LENGTH_SHORT).show();
   ParseUser.logOut();
}
else{
   Toast.makeText(this," null",Toast.LENGTH_SHORT).show();
}

You can find the difference when you run your app, first, it will toast you "yes not null" and after if you run your app again it will show you "null"

Now you can signup your user :) This worked for me. Hope it works for you as well. You can find more info at.

Upvotes: 2

Ahmed Abdelsalam
Ahmed Abdelsalam

Reputation: 168

The reason for this problem is that you may be testing another Parse application on the same virtual device so the user credentials are still used for the new application. So, the solution for this is

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Add this line and run your application
        ParseUser.getCurrentUser().logOut();

Upvotes: 6

Dagi
Dagi

Reputation: 1

I manually cleared the session and I had the same problem while trying to sign up a new user from the same device I signed up previously. Clearing the data for the App in DEVICE settings fixed the problem.

Upvotes: 0

Rishabh Tayal
Rishabh Tayal

Reputation: 496

It seems like a known bug in the Parse SDK. There is already a bug reported on the forum. They claim to have this fixed in the latest version 1.7.3. But it's not working for me either.

Refer to this https://developers.facebook.com/bugs/756392341145634/?search_id

Upvotes: 0

sudheeshcm
sudheeshcm

Reputation: 3418

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);
            }
        });
});

Upvotes: 11

Related Questions