Sign In Register

How can we help you today?

Start a new topic
Answered

GameSparksApi.isAuthenticated() not working

In the docs it says:

Authentication Caching

The SDK stores the auth token from the platform and uses it the next time it connects. This allows the device to remain logged in between application invocations. The authToken from the changes ever time the user connects, and the SDK manages this for you.

You can call the GameSparksApi.isAuthenticated() method to determine if the current player is authenticated or not


However, typing  GameSparksApi.isAuthenticated() doesn't work. Its probably changed to something, please let me know.

I am trying to authenticate the player based on he name in a save file, to pull up his account details, rather than him having to click login every time.


Best Answer

found the answer: 

 

		if(GS.Authenticated)
			print("authenticated");

 


I done this as a temporary workaround:

if player name already exists:


if(ES2.Exists("playerName") && authenticated == false)
{
AuthenticationResponse authResponse = new AuthenticationRequest ().SetUserName(playerName).SetPassword("password").Send();
if (authResponse.HasErrors) {
print("it didnt work");
} else {
print("it worked");
authenticated = true;
}
}


but this doesnt help if the connection is lost when going through a tunnel, I'd have to check if authenticated, or connection has been dropped to the GS servers...

Answer

found the answer: 

 

		if(GS.Authenticated)
			print("authenticated");

 

Would get good to know when player drops connection, so I can display a connection lost screen and hang the game 

Charles, there is a Cloud Code event that is triggered when a Player is Disconnected but this is probably not much use to you in this case as you will have lost connectivity with the back end altogether.  Is it an option for you to put some code into the Update () function on on of the main Unity objects?


if (!GS.Authenticated) {

       // Do something in the game

}


I have a different problem, but it is related to isAuthenticated. If I call: GameSparksApi.isAuthenticated() in the start of the app life cycle, I always get false. So I can't keep the user logged in between app sessions. I have to start over every time.


My code does this:

- checks if isAuthenticated as soon as it starts

- if not (which is always the case), GameSparksApi.deviceAuthenticationRequest().send();  to create a user account no matter what

- then I ask them to login with Facebook, which is optional

- if they do, I successfully login again with Facebook, which should update the anonymous user created above


- If the first isAuthenticated request would be true, I would check if they have Facebook as well.


When I start the app again, I want the user to be automatically logged in all the way. However, when I start the app again, isAuthenticated is always false.


Do I need to to wait for "GS: Available" before I check isAuthenticated?


Thanks in advance!



Hey Måns, did you ever get a solution to your isAuthenticated issue? I am getting the same issue here.

Login to post a comment