Hi all, I’m trying to use the sessian.restore method to jump a previously logged user right into the game.
However the method returns null, as it should since session is really null. What am I missing here?
The docs state that:
Restore a session without having to re-authenticate:
1 var auth_token = "restored from save location"
2 var refresh_token = "restored from save location"
3 session = session.restore(auth_token, refresh_token)
And the github docs state that:
var authtoken = "restored from somewhere"
var session2 = NakamaClient.restore_session(authtoken)
if session2.expired:
print("Session has expired. Must reauthenticate!")
So, in my code, having already saved previously tokens:
var client : NakamaClient
var session : NakamaSession
var auth_token = "user://Nakama/auth.save"
var refresh_token = "user://Nakama/refresh.save"
func _ready():
client = Nakama.create_client(
nakama_server_key,
nakama_host,
nakama_port,
nakama_scheme,
Nakama.DEFAULT_TIMEOUT,
NakamaLogger.LOG_LEVEL.ERROR)
func check_session_restore():
if auth_token == null or refresh_token == null:
pass
else:
#Here I'm testing the doc version:
session = session.restore(auth_token, refresh_token)
#This is a version from the github docs:
var session2 = NakamaClient.restore_session(auth_token)
if session2.is_exception():
print("An error occurred: %s" % session2)
return
The Nakama site’s doc’s output is as follow:
Invalid Call. Nonexistent function 'restore' in base 'Nil'
Basically, session is null.
And the github’s error is as follow:
An error occurred: NakamaException(StatusCode={-1}, Message='{Unable to unpack token: user://Nakama/auth.save}', GrpcStatusCode={-1})
I can see that my first session var is null, should be since I didn’t call anything on it yet. But how am I going to make it not null then? The client is already created, how can I populate this session before calling restore? Sorry if I was caught in the translation, since my native language is not english, but from the docs I could not understand where to go to.
EDIT:
Ok I solved it by adding:
session = yield(client.authenticate_device_async(device_id), "completed")
I link the user’s device upon registration. But there is an error, it says there is NO function “restore” in session. So are the docs mistaken?
The docs that state to use session.restore is here:
Nakama: Godot | Heroic Labs Documentation