Session auth token expires at creation with the official Godot client

Hi, I got the server running with docker-compose and set socket.token_expiry_sec to 604800 (one week). The rest of the settings are the defaults (obtained via the “export” button in the web interface).

I then followed the Godot tutorial and added a few small modifications, but it seems like the session expires right after creation, causing my code to always create a new one using authenticate_device_async.
Did I do anything wrong or is this a bug?
Here is my code (which is autoloaded as a singleton) and the output of running said code. I’ve also added the contents of store.ini just in case:

Code
# GameClient.gd
extends Node

const STORE_FILE = "res://store.ini"
const STORE_SECTION = "nakama"
const STORE_KEY = "session"

var session: NakamaSession = null
onready var client = Nakama.create_client(
	"defaultkey",
	"192.168.99.100",
	7350,
	"http"
)

func _ready() -> void:
	var cfg := ConfigFile.new()
	cfg.load(STORE_FILE)
	var token = cfg.get_value(STORE_SECTION, STORE_KEY, "")

	if token:
		var restored_session = NakamaClient.restore_session(token)
		if restored_session.valid and not restored_session.expired:
			session = restored_session
			print_debug('Authenticated with previously stored session')
			return
	var deviceid := OS.get_unique_id()
	session = yield(client.authenticate_device_async(deviceid), "completed")

	# The following statement seems to always be true:
	print_debug("Is new session expired: ", session.expired)

	if session.is_exception():
		print_debug("Authentication error: ", session.get_exception().message)
		return

	cfg.set_value(STORE_SECTION, STORE_KEY, session.token)
	cfg.save(STORE_FILE)
	print_debug('Authenticated with newly created session')
Output
Is new session expired: True
   At: res://GameClient.gd:30:_ready()
Authenticated with newly created session
   At: res://GameClient.gd:38:_ready()
Contents of store.ini
[nakama]
; This is rewritten every time the code runs
session="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIyMjk2Nzk5MC1iMGY5LTQ4ZDQtODU5MC00MGViYTFkMjhjM2IiLCJ1c24iOiJUaU5nYm9xa1lLIiwiZXhwIjoxNTgzOTIxMjE3fQ.Ast0ItbD7BRJ5Y_-MJkCJ84tqwqp6QXVCyy_7Hjwzt8"

Hi @omrisim210! You’re right that was an issue with the most recent release of the Nakama Godot client.

It was spotted and fixed in this commit but hasn’t yet been packaged into a new release. You can grab the latest code directly off the master branch if you want to test it before the next release. :+1:

That’s great news!

I also had another issue that I’m not sure was related to this - when creating and connecting sockets they wouldn’t emit the connected signal.

What’s strange is that in the beginning they did emit it, but then I started tinkering with the code (to see why sessions weren’t working properly) and they started to only emit the closed signal.

Have you guys received any bug reports about something like this?

If not I can try grabbing the code from the master branch and open an issue if I manage to replicate the bug (if it even is a bug). That is, assuming it isn’t related to this bug.

Definitely sounds odd, we haven’t had any reports about this.

I recommend you update to the latest code from master and see if you can reproduce reliably. If there’s a small reproducible case please put it up on an issue and we’ll look into it. :+1:

1 Like

It seems to be working beautifully so far on master.

Thanks for the help!