Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid sessiontoken when converting anonymous user to signed in user in parse.com

I'm using Swift on iOS.

My app has a list of posts. You can read anonymously but you have to sign up to post.

When you open the app you get an anonymous account. I put the following in AppDelegate

PFUser.enableAutomaticUser()
PFUser.currentUser()?.incrementKey("RunCount")
PFUser.currentUser()?.saveInBackground()

I got the code from: https://www.parse.com/docs/ios/guide#users-anonymous-users

When you go to post I have you sign up

let user = PFUser.currentUser()
user?.username = displayNameTextField.text
user?.password = passwordTextField.text
user?.email = emailTextField.text
user!.signUpInBackgroundWithBlock { ... }

This succeeds. I can see the user being updated on the server. However I get a 209 error: [Error]: invalid session token (Code: 209, Version: 1.7.4)

I have tried looking at the sessiontoken and printing it out at every step and it remains the same. I have heard that sessiontokens are invalidated when a user logs out but I thought I just signed a user in and not out. Why is the sessiontoken invalid?

I have tried setting the user as the current user with PFUser.Become() using the sessiontoken but that does not work either.

I am clearly overlooking something but I can't figure out what. Any help is much appreciate.

like image 507
Christian Hagel Avatar asked Jun 02 '15 03:06

Christian Hagel


1 Answers

The same problem started happening for me, and I realised it was due to enabling this option in the app settings:

Revoke existing session tokens when user changes password - YES/NO

I suspect this is an unintended side-effect of setting a password on an anonymous user - I don't think there's any reason the session token would need to be reset in this case.

Hopefully this will be fixed, but a work-around is to call the logInWithUsername method right after the signUp method succeeds.

like image 196
antsyawn Avatar answered Jan 18 '23 11:01

antsyawn