Hi,
Parse would like you to think in terms of devices, more than users. A Parse Session is a device connection/login from a particular user. The reason for this is that a user could be logged in to your app from multiple devices. These are all considered Sessions to Parse, and you can expect to have multiple entries from the same user, but different devices.
When you provide Parse an “installationId” on each user login you will not have the issue of the Parse Session table filling up. How you derive this “installationId” is completely left to the developer. But Corona SDK does offer some methods to help with this.
You can include the installationId in two different ways.
–
In the config object:
If you put the installationId in the config object, you don’t need to set it in the header each time.
[lua]parse.config:installationId(“YOUR_DERIVED_INSTALLATION_ID”)[/lua]
–
In the header:
[lua]–during signup
parse.request( parse.User.create )
:data({ username=“someone”, email="me@email.com", password=“nopeeking” })
:header(“X-Parse-Installation-Id”, “YOUR_DERIVED_INSTALLATION_ID”)
:response(cb)
–during login
parse.request( parse.User.login )
:options({ username=“someone”, password=“nopeeking” })
:header(“X-Parse-Installation-Id”, “YOUR_DERIVED_INSTALLATION_ID”)
:response(cb)[/lua]
The plugin makes no assumptions about how you store this data between app launches. Its up to the developer to provide that functionality.
Something important to note is that if you want to clear the Parse Session object, you must “logout” the user via the Parse api.
[lua]parse.request( parse.User.logout )
:response(cb)[/lua]
In most cases though, you will want to keep the user “logged-in”, so you can access the Session at a later time.
Getting a previous Session
If you use an installationId, as shown above, Parse will store a Session object for each device. When you login or sign up, you can pull the sessionToken from the results. If you want to retrieve this session – in effect logging in – then you can use:
[lua]parse.request( parse.Session.me )
:header(“X-Parse-Session-Token”, “STORED_SESSION_TOKEN”)
:response(cb)[/lua]
You can also set this in the Config object:
[lua]parse.config:sessionToken(“STORED_SESSION_TOKEN”)[/lua]
Make sure to turn on the debug output to check the payload details:
[lua]parse.config:debugEnabled( true )
parse.config:debugVerbose( true )[/lua]
Most of this is covered in the Parse REST Guide, but I’m not a huge fan on how they relay the information.
I’ve written this quite hastily, so feel free to add questions or point out errors.
Cheers.