Godot Nakama - token auth invalid after server restart

I am using Godot 3.5.3 and image: heroiclabs/nakama:3.10.0 with image: cockroachdb/cockroach:latest-v20.2, and image: prom/prometheus on windows amd64 with Docker Desktop on the side. So, I have the .bat file that I run that does all of the docker-compose -f “%~dp0docker-compose.yml” up which seems to get everything running for server in a cmd window. I have Godot set up and everything is good to go with code (so far). I can create users through registration and as long as the server is running from when I registered a user and logged in, I can find the character info.

The issue is, if I stop the server via closing the cmd window which before closing is shows everything shutting down, nakama, prometheus, cockroachdb, etc. then it closes. If I restart the boot.bat, the server starts up but if I try to log in again, I get === Nakama : DEBUG === Request 2 returned response code: 401, RPC code: 16, error: Auth token invalid.

Im guessing it never invalidates the ticket or something? I dont know what to do with that. I have searched topics and some are ‘similar’ but I couldnt figure it out yet. I found out that it could be the token still active for some reason.

  1. Versions: Nakama {3.20.1}, {Windows, Docker}
  2. I have GO installed but I have no idea if it uses it or not.

I think this is where some of the issue triggers on the else: _ws.poll().

func _process(delta):
	if _ws.get_connection_status() == WebSocketClient.CONNECTION_CONNECTING:
		if _start + _timeout < OS.get_unix_time():
			logger.debug("Timeout when connecting to socket")
			emit_signal("received_error", ERR_TIMEOUT)
	if _ws.get_connection_status() != WebSocketClient.CONNECTION_DISCONNECTED:

This is the last message in the cmd so that looks ok I guess: nakama-1 | {“level”:“info”,“ts”:“2024-02-11T16:47:21.732Z”,“caller”:“main.go:175”,“msg”:“Startup done”}

If I delete the user in the Nakama Console (, I can re-register and it works the first time but I cant shut down the server otherwise it does the error if I start it back up. Thanks if you can help. There is another issue afterwards where I cant join the world but Ill leave that for another topic if I cant get that to work. It worked yesterday and I didnt change ANY code from when I woke up and started testing again. This was all the sudden.

NOTE: I did follow the tutorials both from GDQuest and from your Youtube, they were over an hour videos of setting everything up. :stuck_out_tongue: Thats my reference.

Hey @mojoyup1528 there are two tokens – an auth (short-lived) and a refresh token (long-lived). The refresh token and a fresh auth token are obtained on authentication. The Godot client will automatically refresh the auth token when its close to expiring. But you’ll still need to check is_refresh_expired on your session and reauthenticate when the refresh token is close to expiring.

1 Like

You should also make sure you are on Release - v3.18.0 or greater of the Nakama server and that you’ve set your token expiry times to suitable timeframes. See our configuration here:

1 Like

Good idea, yes I verified that I am using 3.20+ :slight_smile: Though I havent messed yet with expiration times and I know that is a push on developers to pay attention to that ;). Ill find it and play around with the timing!