Cannot create a username/password user from an anonymous user
Hi,
I am running the latest version of the parse-server on my local server. My client is an iOS app. I create an anonymous user with the following code: PFAnonymousUtils.logInWithBlock
At a certain point in my app, I want to convert this anonymous user to a normal user. I can convert it to a Facebook, Twitter or username/password user. With FaceBook or Twitter, I use their "linkUser" method and everything works fine. With the username/password, I do the following:
var user = PFUser.currenUser()
user.username = username?.lowercaseString
user.email = username?.lowercaseString
user.password = password
user.signUpInBackgroundWithBlock { (sucess, error) in
}
When I look at the "Session" table in mongoDB, there is no session created. In fact, the session that was created for the anonymous user was deleted when I tried to transform the anonymous user to a username/password user. If I log out and log in again, the session is properly created.
Is there a way to link the anonymous user to a username/password user?
Environment Setup
- Server
- parse-server version: 2.2.16
- Operating System: Mac OS X El Capitan
- Hardware: MacBook Pro
- Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): localhost
- Database
- MongoDB version: 3.2.1
- Storage engine: [FILL THIS OUT]
- Hardware: [FILL THIS OUT]
- Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): [FILL THIS OUT]
Logs/Trace
You can turn on additional logging by configuring VERBOSE=1 in your environment.
[Error]: invalid session token (Code: 209, Version: 1.13.0)
I have also experienced this issue in #2193 . Hopefully a fix is contributed, but until then, I recommend logging in after signing up to generate that session token on the server.
You should use the save function instead of the signUp function IMHO as the anonymous user is already saved.
@flovilmart It still doesn't work. I take my anonymous user and tries to save him. Once it is saved, I still see the "anonymous id" in the "authData" and the session row has disappeared from the Session table.
Can you please provide the logs when running with VERBOSE=1?
Creating the anonymous user
parse-server-0 verbose: POST /parse/users { host: 'localhost:1337', parse-server-0 'x-parse-client-version': 'i1.13.0', parse-server-0 accept: '/', parse-server-0 'x-parse-application-id': '_', parse-server-0 'x-parse-client-key': '', parse-server-0 'x-parse-installation-id': '_*', parse-server-0 'accept-language': 'en-us', parse-server-0 'x-parse-os-version': '9.3 (15F34)', parse-server-0 'accept-encoding': 'gzip, deflate', parse-server-0 'content-type': 'application/json; charset=utf-8', parse-server-0 'content-length': '72', parse-server-0 'user-agent': 'MyApp/2.3 CFNetwork/758.3.15 Darwin/15.5.0', parse-server-0 connection: 'keep-alive', parse-server-0 'x-parse-app-build-version': '2.3', parse-server-0 'x-parse-app-display-version': '2.3' } { parse-server-0 "authData": { parse-server-0 "anonymous": { parse-server-0 "id": "73ef1c6c-cf28-4435-8cba-fadebcb53214" parse-server-0 } parse-server-0 } parse-server-0 } parse-server-0 verbose: { parse-server-0 "status": 201, parse-server-0 "response": { parse-server-0 "objectId": "yEUq1rscv6", parse-server-0 "createdAt": "2016-07-12T18:10:11.471Z", parse-server-0 "username": "VJERDU25CWVNFMwv2SiuAFHPF", parse-server-0 "sessionToken": "r:8439d3a0ccaec43801180062f6da9445" parse-server-0 }, parse-server-0 "location": "localhost:1337/parse/users/yEUq1rscv6" parse-server-0 }
Saving it to become a normal user
parse-server-0 verbose: PUT /parse/classes/User/yEUq1rscv6 { host: 'localhost:1337', parse-server-0 'x-parse-client-version': 'i1.13.0', parse-server-0 accept: '/', parse-server-0 'x-parse-session-token': 'r:8439d3a0ccaec43801180062f6da9445', parse-server-0 'x-parse-application-id': '*******************', parse-server-0 'x-parse-client-key': '', parse-server-0 'x-parse-installation-id': '_********_', parse-server-0 'x-parse-os-version': '9.3 (15F34)', parse-server-0 'accept-language': 'en-us', parse-server-0 'accept-encoding': 'gzip, deflate', parse-server-0 'content-type': 'application/json; charset=utf-8', parse-server-0 'content-length': '146', parse-server-0 'user-agent': 'MyApp/2.3 CFNetwork/758.3.15 Darwin/15.5.0', parse-server-0 connection: 'keep-alive', parse-server-0 'x-parse-app-build-version': '2.3', parse-server-0 'x-parse-app-display-version': '2.3' } { parse-server-0 "email": "[email protected]", parse-server-0 "username": "[email protected]", parse-server-0 "password": "_", parse-server-0 "firstName": "John", parse-server-0 "lastName": "Doe", parse-server-0 "authData": { parse-server-0 "anonymous": null parse-server-0 } parse-server-0 } parse-server-0 verbose: { parse-server-0 "response": { parse-server-0 "updatedAt": "2016-07-12T18:12:34.030Z" parse-server-0 } parse-server-0 }
At that time, the session doesn't exist anymore in the Session table, and any attempt results to error 209.
Thanks, we'll have a look
FYI, I did what @noder199 suggested. I saved my anonymous user then logged in just after the save and the session was created. But I think this is just a workaround. I will let you investigate this. Thanks for the support.
You can also try to fix that bug and open a PR :)