RefreshToken won't change from Null and Session won't expire/refresh


I was trying to setup the username change feature in my game in Unity with Typescript and Postgres as language and db for Nakama. When I tried executing the code, the following error message appeared:

ApiResponseException(StatusCode=400, Message='Refresh token is required.', GrpcStatusCode=3)

That’s when I realized that my Session didn’t have any refresh token. A quick printout confirmed it:

Session(AuthToken='ey[...]A', Created=False, CreateTime=41, ExpireTime=1712723134, RefreshToken=, RefreshExpireTime=0, Variables={}, Username='Tatataaaa', UserId='ce54ce79-3abb-4770-8b27-ac51c827dfdf')

What is even weirder is the username getting stuck at a username that I was able to setup once but couldn’t do it again. Even when I restart my Docker Nakama, the data just doesn’t want to go away.

I tried to change my docker-compose file with the following:

      - "/bin/sh"
      - "-ecx"
      - >
          /nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama &&
          exec /nakama/nakama --name nakama1 --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama --logger.level DEBUG --session.token_expiry_sec 30 --session.refresh_token_expiry_sec 30

and the local.yml file like this:

name: nakama-node-1
data_dir: "./data"

    stdout: true
    level: "warn"
    file: "/nakama/data/logfile.log"

  js_entrypoint: "build/index.js"

    port: 7351
    username: "root"
    password: "password"

  token_expiry_sec: 30
  refresh_token_expiry_sec: 30

When I run docker-compose up --build, I get the following inputs during launch:

postgres  | 2024-04-03 05:48:34.493 UTC [1] LOG:  database system is ready to accept connections
nakama    | + /nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama
nakama    | {"level":"info","ts":"2024-04-03T05:48:37.834Z","caller":"migrate/migrate.go:155","msg":"Database connection","dsn":"postgres://postgres:xxxxx@postgres:5432/nakama?sslmode=prefer"}
nakama    | {"level":"info","ts":"2024-04-03T05:48:37.840Z","caller":"migrate/migrate.go:203","msg":"Database information","version":"PostgreSQL 12.2 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.2.0) 9.2.0, 64-bit"}
nakama    | {"level":"info","ts":"2024-04-03T05:48:37.842Z","caller":"migrate/migrate.go:226","msg":"Successfully applied migration","count":0}
nakama    | + exec /nakama/nakama --name nakama1 --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama --logger.level DEBUG --session.token_expiry_sec 30 --session.refresh_token_expiry_sec 30
nakama    | {"level":"info","ts":"2024-04-03T05:48:37.854Z","caller":"server/config.go:90","msg":"Successfully loaded config file","path":"/nakama/data/local.yml"}
nakama    | {"level":"warn","ts":"2024-04-03T05:48:37.854Z","caller":"server/config.go:325","msg":"WARNING: insecure default parameter value, change this for production!","param":"console.password"}
nakama    | {"level":"warn","ts":"2024-04-03T05:48:37.854Z","caller":"server/config.go:329","msg":"WARNING: insecure default parameter value, change this for production!","param":"console.signing_key"}
nakama    | {"level":"warn","ts":"2024-04-03T05:48:37.854Z","caller":"server/config.go:333","msg":"WARNING: insecure default parameter value, change this for production!","param":"socket.server_key"}
nakama    | {"level":"warn","ts":"2024-04-03T05:48:37.854Z","caller":"server/config.go:337","msg":"WARNING: insecure default parameter value, change this for production!","param":"session.encryption_key"}
nakama    | {"level":"warn","ts":"2024-04-03T05:48:37.854Z","caller":"server/config.go:341","msg":"WARNING: insecure default parameter value, change this for production!","param":"session.refresh_encryption_key"}        
nakama    | {"level":"warn","ts":"2024-04-03T05:48:37.854Z","caller":"server/config.go:345","msg":"WARNING: insecure default parameter value, change this for production!","param":"runtime.http_key"}
nakama    | {"level":"info","ts":"2024-04-03T05:48:37.854Z","caller":"main.go:113","msg":"Nakama starting"}

I feel like I am missing an important concept and way of doing with Nakama. Would be really appreciated if someone could go a bit in detail while explaining what is happening here.

Thank you a lot!

@StudioParaNoya what version of Nakama and client SDK are you running?

For nakama: image:
For the SDK: Version 3.10.1

Refresh Token rotation was introduced in Nakama v3.18.0, in your current version the refresh token can only be used once, so in your session the token was likely already refreshed once. I’d suggest you upgrade Nakama to latest (v3.21.1) which will allow refresh tokens to be rotated.

Hope this helps.

I applied the new version by doing that: image:

I also deleted all my images, containers and volumes in Docker Desktop as well as deleting everything in PlayerPrefs.

My session seemed to have been forgotten due to all the deletions, I was able to see one refresh token but it disappeared when I refreshed. The following were in the Session:
CreateTime=35, ExpireTime=1712270680, RefreshToken=, RefreshExpireTime=0

I still don’t understand why the ExpireTime is so high when I have this in my docker-compose:
–session.token_expiry_sec 30 --session.refresh_token_expiry_sec 30

I am not sure why this is happening. I will reach to the support team and see if I can schedule a call.

Thanks for the help

ExpireTime is a Unix epoch, I don’t know when it was created but should be correct? Either way I’m not sure why the RefreshToken is not set, I don’t think this is an issue we’ve seen before. The refresh token expiry should be set to a higher value than the token expiry (I’d say at least its double).