How can I refresh a cached username after it has been updated?

I’m seeing some unexpected behavior when updating usernames.

When the client sends a Username update to the server I can see the new Username in the Developer Console. But if I then try to fetch the Username I get the old Username back.

If I close my app and then relaunch it, initiating a new session, my fetch will then return the updated Username.

So it appears that updating the Username takes effect immediately on the server side, but I cannot fetch the updated name until I start a new session.

This is not the case for DisplayNames. If I update the DisplayName, then fetch it immediately I get the updated value back.

I’m wondering if this is intended, or if I’m doing it wrong?

At the moment I’m working on a very lightweight app that does not store any persistent information about the user. I ask them to enter their name every time they launch the program. Since Nakama stores the original username, I just send a username update with the entered value immediately after authenticating.

I can get the behaviour I want if I update and fetch DisplayNames and then only work with DisplayNames in my UI. This is fine for now, but as I build out my architecture I want to better understand how updating UserNames work.

Am I correct in understanding that I cannot fetch an updated Username until the next session or is there something else at play here?

I’d like to “get it” so I can build around it appropriately. Thanks!

@Mehoo462 The user ID and username for a user is cached in a session token when an authorized context is created (a user authenticates with one of the options supported by the server). If you’d like to refresh the session immediately after the username is changed you can manually trigger it with client.SessionRefreshAsync function.

1 Like

I’m finally getting around to giving this a shot. I’m not finding a “SessionRefreshAysnc” function on my client object. Nor my session object.

Perhaps I’m misunderstanding? Could you provide more details about where to find this function? I’m using the C++ client, Release 2.5.0. Thanks!

Hi, is there any update on this?

I might be doing it wrong, but I’m unable to find client.SessionRefreshAsync function anywhere in the C++ SDK. I would love to implement this feature, but I’m not finding what you’re referring to.

Any assistance would be much appreciated. Thank you!

@Mehoo462 You’re right it looks like it was missed from the CPP client. You can find an example implementation of it in the .NET client:

If you have time it would be great to open a pull request with it on the CPP client. Thanks :pray: