Godot session vars doesn't work during authentication

Hey everyone,

It seems that session vars can’t be sent through authentication. I dived in and found a fix that imply modifying Nakama godot module. Here are some notable points :

1. Documentation about session vars in Godot is invalid

var vars = {
    "device_os" = OS.get_name,
    "device_model" = OS.get_model_name,
    "invite_user_id" = "<some_user_id>,
    # ...
}

var session : NakamaSession = yield(client.authenticate_device_async("<device_id>", null, true, vars), "completed")

This is not how we declare a dictionnary in Godot. I did the following

var vars = {
    "somekey" : "somevalue",
}

var session : NakamaSession = yield(client.authenticate_device_async("<device_id>", null, true, vars), "completed")

2. Nakama serializer does not handles dictionnary in NakamaSerializer.gd

		TYPE_DICTIONARY: # Maps
			var dict = {}
			if content == TYPE_OBJECT: # Map of objects
				for l in val:
					if val_type != TYPE_OBJECT:
						continue
					dict[l] = serialize(val)
			else: # Map of simple types
				for l in val:
					dict[l] = val[l]
					if val_type != content:
						continue
					dict[l] = val

It seems that the dict defined here is never added to the “out” variable that is returned. Which basically mean that the dict var is declared but never used. It also seems that “val_type” is never equal to “content”.

To be 100% honest, i’m not totally sure to understand how the whole serializer works, but what I know is that it remove the “vars” defined in the authenticate function and nothing is sent.

I did a quick and dirty fix, but this might not be the real solution to that :

			TYPE_DICTIONARY: # Maps
				var dict = {}
				if content == TYPE_OBJECT: # Map of objects
					for l in val:
						if val_type != TYPE_OBJECT:
							continue
						dict[l] = serialize(val)
				else: # Map of simple types
					for l in val:
						dict[l] = val[l]
					out[k] = dict

But maybe my problem comes from the vars definition. Is it supposed to be a dictionnary ?

Thanks in advance for your help ;).

Hello @rretureau,

Yes, the vars are supposed to be a dictionary. The documentation is in my view correct and is just showing you a sample of what type of data you could pass as session vars.

A fix to dictionary de-serialization has been merged recently (Correctly (de-)serialize floats in dictionaries to fix "numeric_prope… · heroiclabs/nakama-godot@cdbcf2c · GitHub) and may be related your issue, can you update to the latest version and check if it is resolved?

Thanks for your answer.

For the dictionnary, there is a structural error in the exemple ( “=” symbol instead of “:” in the dictionnary definition). That’s what I am referring to.

For the version, i’m already using the latest version and the fix does not seems to work.

The “=” is an accepted alternative Lua-style syntax, but you’re correct that the example is wrong as this syntax only accepts string literals. Thanks, we’ll fix that :pray:

If you’re already using the latest version, can you open an issue on the Github repo please? It seems that you removed the type check and it worked, so please post that there too and we’ll look to fix it.