Invalid session token when converting an anonymous user to a signed-in user at parse.com

I am using Swift on iOS.

My application has a list of messages. You can read anonymously, but you must register to post.

When you open the application, you get an anonymous account. I added the following to 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 the mail, I sign up

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

It succeeds. I can see how the user is being updated on the server. However, I get error 209: [Error]: invalid session token (code: 209, version: 1.7.4)

I tried looking at the sessiontoken and printing it at every step, and it remains the same. I heard that sessiontokens are not valid when the user logs out, but I thought I just signed up the user and did not log out. Why is sessiontoken invalid?

I tried to configure the user as the current user using PFUser.Become () using sessiontoken, but this does not work either.

I am clearly missing something, but I can't figure that out. Any help is greatly appreciated.

+7
ios swift
source share
2 answers

The same problem arose for me, and I realized that this was due to the inclusion of this option in the application settings:

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

I suspect this is an unforeseen side effect of setting a password for an anonymous user. I do not think that in this case the session token should be reset.

I hope this is fixed, but a workaround is to call the logInWithUsername method immediately after the signUp method completes successfully.

+11
source share

You login incorrectly, try

 func login() { var user = PFUser() user.username = "myUsername" user.password = "myPassword" user.signUpInBackgroundWithBlock { (succeeded: Bool, error: NSError?) -> Void in if let error = error { let errorString = error.userInfo?["error"] as? NSString // Show the errorString somewhere and let the user try again. } else { // Hooray! Let them use the app now. } } } 

The code let user = PFUser.currentUser() shows only the user who is currently logged in.

You also need to authenticate with Parse before you can create any request, the best place for this is in appDelegate inside the didFinishLaunchingWithOptions function

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { Parse.setApplicationId("Your Id go Here", clientKey: "Your clientKey go here") return true } 

Values ​​for ID and clientKey are available in Parse and are unique to your accont

I hope this helps, good luck!

0
source share

All Articles