question

racso avatar image
racso asked

Obtaining the currently logged in user ID without a new request

Let's assume that I log in a user by any method, e.g. LoginWithCustomID.

I can check that I'm logged in by using IsClientLoggedIn(). Is there a way to obtain the ID of the currently logged in user? For example, something like PlayFabClientAPI.GetLoggedUserId() or similar.

I know that I can make a request asking for the currently logged user information to retrieve the ID, but a new request shouldn't be necessary for that (as it isn't necessary to make a new request to see if the client is logged in). I also know that every LoginResult contains the ID, but I don't want to store the ID myself if I don't need to, as I'd need to keep that stored ID synced with the PlayFab login process.

Thanks.

unity3dAuthentication
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

what do you mean "keep that stored ID synced with the PlayFab login process"? what is your specific need?

After the login, a session ticket will be generated and it will be stored in your client background. Then, all the client API will be using that session ticket. For example, in the request of GetPlayerProfile API, you can leave out the PlayFabId property when you make the call. Sever will automatically respond the the profile of current logged-in player.

in normal circumstance, you have to store the additional information if you are about to use them somewhere else. Global variables need to be created to store them. In the successful callback of login API such as LoginWithCustomID, you can retrieve the expiration date (in Unity/C# ) via:

onSuccessCallback.EntityToken.TokenExpiration
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

racso avatar image racso commented ·

Thanks for the answer.

We're currently developing our login/linking system, and I simply wanted to display the user PlayFab ID during testing. I noticed that the only place where I could get it was in the callback after logging in.

When I mentioned that you need to "keep the stored ID synced", I was talking about the "global variables" you mention: you'd need to set the global variable when you login, make sure you clear it when you log out, and handle special cases (such as the expiration of the token; if you don't update the global variable when the token expires, it will get "out of sync" with the PlayFab API).

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ racso commented ·

>>the only place where I could get it was in the callback after logging in

Yes, you are right.

the token will last for 24 hours unless the same account has been logged in before the expiration time (which will generate a new one).

I think you can keep the PlayFab ID, because it is comparatively safe. You can update this global variable only when you switch to other accounts.

Some people will keep the authentication information for a silent login feature in a game, not to mention PlayFab ID. But if you want to be more safe, it is fine to clear it when the token expires.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.