# Session auth token expires at creation with the official Godot client

**URL:** <https://forum.heroiclabs.com/t/session-auth-token-expires-at-creation-with-the-official-godot-client/545>\
**Category:** Local Setup\
**Tags:** getting-started\
**Created:** [March 4, 2020, 10:16am UTC](https://forum.heroiclabs.com/t/session-auth-token-expires-at-creation-with-the-official-godot-client/545 "2020-03-04T10:16:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![omrisim210](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@omrisim210](https://forum.heroiclabs.com/u/omrisim210)\
**Post date:** [March 4, 2020, 10:16am UTC](https://forum.heroiclabs.com/t/session-auth-token-expires-at-creation-with-the-official-godot-client/545/1 "2020-03-04T10:16:20Z")

</div>

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**
>
> ```auto
> # 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"
> 
> ```

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [March 4, 2020, 11:02am UTC](https://forum.heroiclabs.com/t/session-auth-token-expires-at-creation-with-the-official-godot-client/545/2 "2020-03-04T11:02:48Z")

</div>

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](https://github.com/heroiclabs/nakama-godot/commit/13222a7af9fbfa25490017e498ef2632106d2ced) 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. 👍

---

<div class="post-metadata">

**Author:** ![omrisim210](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@omrisim210](https://forum.heroiclabs.com/u/omrisim210)\
**Post date:** [March 4, 2020, 2:12pm UTC](https://forum.heroiclabs.com/t/session-auth-token-expires-at-creation-with-the-official-godot-client/545/3 "2020-03-04T14:12:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [March 4, 2020, 2:24pm UTC](https://forum.heroiclabs.com/t/session-auth-token-expires-at-creation-with-the-official-godot-client/545/4 "2020-03-04T14:24:01Z")

</div>

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](https://github.com/heroiclabs/nakama-godot/issues) and we’ll look into it. 👍

---

<div class="post-metadata">

**Author:** ![omrisim210](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@omrisim210](https://forum.heroiclabs.com/u/omrisim210)\
**Post date:** [March 5, 2020, 12:31pm UTC](https://forum.heroiclabs.com/t/session-auth-token-expires-at-creation-with-the-official-godot-client/545/5 "2020-03-05T12:31:08Z")

</div>

It seems to be working beautifully so far on `master`.

Thanks for the help!
