Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse for javascript - "error 209 invalid session token" when signing up a new user

I wrote a simple function in an angularJS application for signing up new users:

$scope.registerUser = function(username, password) {
    var user = new Parse.User();
    user.set("username", username);
    user.set("email", username);
    user.set("password", password);

    user.signUp(null, {
      success: function(result) {

        console.log(result);
        $scope.registerUserSuccess = true;
        $scope.registerUserError = false;
        $scope.registerUserSuccessMessage = "You have successfully registered!";

        $scope.$apply();

        $timeout(function(){
            $state.go("user");
        }, 1000);

      },
      error: function(user, error) {
        $scope.registerUserError = true;
        $scope.registerUserSuccess = false;
        $scope.registerUserErrorMessage = "Error: [" + error.code + "] " + error.message;
        $scope.$apply();
      }
    });

Initially it worked fine, but when I deleted all the users directly through Parse.com, I can't sign up new users using this function anymore. Each time I get error 209 invalid session token. Here's a screenshot of my Parse database:

enter image description here

I've googled the error message and the solution is always to log out the current user. However, if no users exist this isn't an action I can possibly take.

So I would not only like to fix this problem, but also know how to prevent it in the future so my application can be used safely.

Edit: I created a user directly in Parse.com, wrote a function to log in that user, but got the same error. I am completely stuck until this session issue is resolved.

like image 967
ericgrosse Avatar asked Aug 19 '15 19:08

ericgrosse


2 Answers

delete all your session tokens, and anything else Parse related really, from local storage:

enter image description here

if needed turn off legacy session tokens, and follow migration tutorial from scratch:

enter image description here

like image 130
slupek2013 Avatar answered Jan 01 '23 22:01

slupek2013


I encountered this same error when building apps with react native using back4app. to clear anything Parse related, from local storage:

add

import { AsyncStorage } from "react-native";

in to the page and Use

AsyncStorage.clear();

See Example Below:

import { AsyncStorage } from "react-native";
import Parse from "parse/react-native";

// Initialize Parse SDK
Parse.setAsyncStorage(AsyncStorage);
Parse.serverURL = "https://parseapi.back4app.com"; // This is your Server URL
Parse.initialize(
  "APPLICATION_ID_HERE", // This is your Application ID
  "JAVASCRIPT_KEY_HERE" // This is your Javascript key
);
 .........


  _handleSignup = () => {

    // Pass the username, email and password to Signup function
    const user = new Parse.User();
    user.set("username", "username);
    user.set("email", "email");
    user.set("password", "password");

    user.signUp().then(user => {
         AsyncStorage.clear();
        if (condition) {
          Alert.alert(
            "Successful!",
            "Signin Successful! Log in to your account.",
             [
              {
                text: "Proceed",
                onPress: () => {
                  //in this example, i navigated back to my login screen
                  this.props.navigation.navigate("LoginScreen");
                }
              }
            ],
            { cancelable: false }
          );
        }
      })
      .catch(error => {
        Alert.alert("" +error);
      });
  };
like image 28
Abiodun Adenle Avatar answered Jan 01 '23 23:01

Abiodun Adenle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!