Is there an easy way (perhaps similar to the after authentication hooks) to detect when a session has been restored?

  1. Versions: Nakama{3.20.1, Docker, JS client
  2. Server Framework Runtime language: Go, TS/JS

Our game is updated frequently, and there are sometimes changes/initializations that we want to ensure after releasing a new version.

Therefore, my question is basically: Is it possible to “catch” a Session restore? Judging by the source code, restoring a session, even after a server reboot, doesn’t make any calls to the server unless it is expired (which makes sense)- however I would like to execute some possible initializations of metadata if needed. The most logical place to do this seems to be in the after authenticate * hooks. But, naturally, these are not called when a session is restored.

Some of the possible solutions could be:

  • Use an RPC to execute an initialization after authentication and/or session restoration from the frontend;
  • Force log out everybody on the server after- or directly before rebooting and/or destroying any and all existing sessions to force a re-authentication;
  • Execute the initialization checks before any RPCs and/or Matches that would need to use the metadata.

Before I implement any one of these, I would love to hear if there’s possibly a better solution that I’m not seeing or I can’t find in the documentation.

Thanks!

Typically this is done as part of something benign like GetAccount that the client does during its own game startup - essentially a BeforeHook of sorts on the first call after authentication that the client makes to the server.

Alternatively Hiro has this built in where you can define (and redefine) what the player “inventory” should be and this is automatically managed by Hiro for you.