Manually changing the sessionId / persistent character

What are the options in Colyseus for creating a persistent character that remains in the state once the client leaves? More specifically, I want to use the same character once the player reconnects. My first thought is to use a sessionId that is linked to the account of the player in colyseus/social, however, I am not able to find a way to modify the sessionId. Any ideas about how I might achieve this? Thank you in advance.

Hi !

If your room is set to autoDispose = false ( the state is kept, so can keep your character data in. And then with a reconnection, the data can be retreived with the session id.

but the data will still be lost if the Room is closed and you cant change that... A room is a temporary instance of your game, thats why you should store your informations on a dedicated database :)

Hey, @SauceCodeFr I use the exact same concept but the problem I am experiencing (just noticed I didn't clarify this in my post) is that on every reconnection the client uses a different sessionId and I am not able to change it.

This behaviour is normal, a session id means not an id attribued to your user, just an id attribued to his session. If you want to keep an id across browser restarts you must implement authentication !

And store data assigned to the user email address or something. You may also want to use for retreiving user informations. But it need to store this in another database than your room state.

@saucecodefr I am doing exactly this but I do not know how to tell the client what his sessionId is. I cannot override it onJoin.

Why overriding sessionId by forcing yours ? Just add another variable send via the state or message, something like userId. Session should be volatile, but user id should be persistent.