Sign In Register

How can we help you today?

Start a new topic
Answered

Log out?

I can't find any code examples or methods in the SDK for logging the client out of GameSparks.  How do I log the user out? (Unity SDK)


Best Answer

I managed to find some example code with GS.Reset() being used for logging out in the Unity client.  Tested it and it works well.  If I'm logged in with FB, then I need to also call FB.Logout at the same time.


If you need to disconnect from the client you can use GS.Disconnect()
from cloud-code you can use Spark.getPlayer().disconnect(true);

 

Answer

I managed to find some example code with GS.Reset() being used for logging out in the Unity client.  Tested it and it works well.  If I'm logged in with FB, then I need to also call FB.Logout at the same time.

Hey Rich!

Could you please provide the code you're talking about?
Failed to find it myself :(

I'm having the same issue. It really is not clear to me how to force a logout. In fact, even when I stop unity and restart it, GS.Authenticated becomes TRUE quickly without me doing any kind of login.


I also see that  GS.GSPlatform.UserId stays stuck to a given id even when I call GS.Disconnect, or GS.Reset, or when I log in with a different user. That's really odd. It feels like the Unity SDK is not supporting login with different users on the same machine.


Am I missing something ?


Does anyone have code to logout properly and prevent authentication to happen "by magic" ? 

@  François

Did you confirm that you are not getting a new user auth after calling GS.Disconnect?


Our current login requires Authentication before entering the game. We change users without even calling disconnect because authenticating ends the previous credentials and returns account data from the new login.  In other words, we get multiple players on one device without explicit log out and support multiple users on one device - one at a time.


On a local log out call, we put a login in front of the player, they can either login or register. There is not a way to proceed without either. This method does not support 'remember me' or autologin or sustained sessions etc.


If you are allowing the user in based on GS.Authenticate, you should make sure you are not accepting device auth - there is only one allowed per machine. You will want to make sure you are allowing access on login and password credentials, and that the pair return with no errors. 


I believe there is sample code for Unity. in a script called something like gs_RegisterPlayers.

USe `GameSparks.Api.Requests.RegistrationRequest`

or `GameSparks.Api.Requests.AuthenticationRequest`

and not `DeviceAuthenticationRequest`

Login to post a comment