Issue when updating username with account_update_id

Hello guys,

I have a problem when updating the username of an user with account_update_id method in lua. The leaderboard_record table is not updated and so when we get the haystack for that tournament the user will appear with the old username instead of the new one - generating multiple issues.

Is this a known bug?

Thanks

@vladmustiata This is not a bug but by design. There’s a few details to consider on how Nakama stores and manages usernames. The session token for a user contains a number of cached fields which make values like user ID, username, etc available without a database request or centralized session cache.

An example of the contents of a Nakama session token:

{
  "uid": "e619c96e-3c5a-4895-8828-cccb7fa39f9e",
  "usn": "YURiegFSJW",
  "vrs": {
  },
  "exp": 1608593956
}

You can see the "usn" and "uid" in the decoded token.

When the username is updated in the account for the player you should then refresh their token with a new authentication (this will be easier in newer releases of the server - see https://github.com/heroiclabs/nakama/pull/466) which will return a new session token for that user.

Please note that even with the username updated and reflected into the session token it will not cause the leaderboard/tournament records to be updated which have already been written. As you can imagine to update all score records for the user would be expensive with the database. If you want to achieve this you can manage it yourself with an after hook on the AccountUpdate request which writes 0 value scores to the leaderboards for the player - in this case the username field will be updated but based on the score operator for the leaderboard the new score can just be ignored.

These design decisions ensure that the system scales exceptionally well and limits the IO pressure on the database.

Hope this helps.

2 Likes