Hi!
I’ve been trying to run a server-authoritative project… I’ve gotten it running on my local docker machine running on VirtualBox, but when I upload the lua files to our remote deployed nakama server and docker-compose down then up the machine, I’m getting this error:
my-nakama | {"level":"debug","ts":"2019-08-09T19:52:28.753Z","msg":"Could not write storage object, exec error.","object":"collection:\"collection\" key:\"key1\" value:\"{\\\"jsonKey\\\":\\\"jsonValue\\\"}\" ","query":"INSERT INTO storage (collection, key, user_id, value, version, read, write, create_time, update_time) VALUES ($1, $2, $3::UUID, $4, $5, $6, $7, now(), now())","error":"ERROR: foreign key violation: value ['9b7ba952-ace9-4eaf-8792-12e7c34d3fb6'] not found in users@primary [id] (txn=f036a618-f6d2-4189-9c53-473acbc89944) (SQLSTATE 23503)"}
I’m trying to write these storage objects for testing:
client.writeStorageObjects(currentSession, [{ "collection": "collection", "key": "key1", "value": {"jsonKey": "jsonValue"} }]);
The front-end is a web browser game in JavaScript by the way.
Seems like the issue is that the user is deleted from the database (probably via the Developer Console, or direct SQL manipulation) but they have a cached session on the client and are still interacting with the system.
Never delete users from the system without rotating the session encryption key which in turn will invalidate all session tokens in the wild.
Hm. We’re using a freshly booted and created Nakama docker machine.
I’m wondering why the problem exists on the remote machine, but not on local?
Are you using the same session encryption key on both the local server and the remote server?
This would mean that a client device connecting to the local server, authenticating and then caching the token - can connect to the remote server actually make API calls with the cached token.
Please make sure your session encryption keys are unique between servers.
Okay I tried uploading the front-end code to my other server, and opened it from a new browser that I haven’t tried the project on yet, so it’s not using a cached token, and I’m getting the same result.
If you are getting the same exact error:
['9b7ba952-ace9-4eaf-8792-12e7c34d3fb6'] not found in users@primary
Means that you are trying to use the same session token that has that User ID embedded inside it. This means you are reusing the same token. Please open your browser window in incognito mode, or as I mentioned, change your session encryption key:
https://heroiclabs.com/docs/install-configuration/#session