From 2643fe4276fc7763ede36565919329b692a17c17 Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 1 Mar 2026 10:57:15 -0500 Subject: [PATCH] =?UTF-8?q?client:=20fix=20auth=5Ffailed=20loop=20?= =?UTF-8?q?=E2=80=94=20logout=20+=20navigate=20from=20Auth.gd=20centrally?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When auth.hello is rejected (session expired/revoked), Auth.gd now calls logout() to wipe all auth state (including auth.cfg) and drives the scene change to LoginScreen directly, instead of relying on each scene's own auth_failed handler. This covers all screens (main, collection, etc.) without each needing a handler, and eliminates the race where the auth.hello reply arrived as DISCONNECTED (STATE_CLOSING path, token kept) → reconnect → resend token. main_screen.gd no longer subscribes to auth_failed; session expiry redirect is fully owned by Auth.gd. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- Client/origin-client/autoloads/Auth.gd | 15 ++++++++++----- Client/origin-client/scenes/main/main_screen.gd | 16 ++-------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/Client/origin-client/autoloads/Auth.gd b/Client/origin-client/autoloads/Auth.gd index 4f3e1df..cb27fba 100644 --- a/Client/origin-client/autoloads/Auth.gd +++ b/Client/origin-client/autoloads/Auth.gd @@ -101,12 +101,17 @@ func _on_network_connected() -> void: { "sessionToken": session_token }, func(_type: String, p: Variant): _on_auth_ok(p), func(code: String, msg: String): - # Keep the token on network errors — we'll retry on the next - # reconnect. Only clear it on explicit auth rejections. - if code != "DISCONNECTED": - session_token = "" - _save_session() + if code == "DISCONNECTED": + # Transient network drop — keep the token and retry on reconnect. + auth_failed.emit(code, msg) + return + # Session explicitly rejected (expired / revoked / invalid). + # Wipe all auth state, emit the failure, then drive the scene + # change here so every screen (main, collection, etc.) is covered + # without each needing its own auth_failed handler. + logout() auth_failed.emit(code, msg) + get_tree().change_scene_to_file("res://scenes/login/LoginScreen.tscn") ) diff --git a/Client/origin-client/scenes/main/main_screen.gd b/Client/origin-client/scenes/main/main_screen.gd index f416fba..db9defc 100644 --- a/Client/origin-client/scenes/main/main_screen.gd +++ b/Client/origin-client/scenes/main/main_screen.gd @@ -4,8 +4,8 @@ extends Control ## Displays the player's display name and live connection status. ## Placeholder navigation buttons for future game features. ## -## If auth.hello re-validation fails after a reconnect (expired session), -## Auth.auth_failed fires and we redirect back to the login screen. +## Session expiry is handled centrally by Auth.gd, which calls logout() and +## navigates to LoginScreen when auth.hello is rejected on reconnect. @onready var welcome_label : Label = %WelcomeLabel @onready var status_label : Label = %StatusLabel @@ -20,7 +20,6 @@ func _ready() -> void: Network.connected.connect(_update_status) Network.disconnected.connect(_update_status) - Auth.auth_failed.connect(_on_auth_failed) logout_btn.pressed.connect(_on_logout_pressed) collection_btn.pressed.connect(func(): get_tree().change_scene_to_file("res://scenes/collection/CollectionScreen.tscn")) @@ -33,8 +32,6 @@ func _exit_tree() -> void: Network.connected.disconnect(_update_status) if Network.disconnected.is_connected(_update_status): Network.disconnected.disconnect(_update_status) - if Auth.auth_failed.is_connected(_on_auth_failed): - Auth.auth_failed.disconnect(_on_auth_failed) # ── Signal handlers ─────────────────────────────────────────────────────────── @@ -47,15 +44,6 @@ func _update_status() -> void: status_label.modulate = Color(1.0, 0.8, 0.2) -func _on_auth_failed(error_code: String, _message: String) -> void: - if error_code == "DISCONNECTED": - # Transient drop during auth.hello retry — stay on screen. - # _update_status() already shows "● Reconnecting…" via the disconnected signal. - return - # Session explicitly rejected (expired, revoked, locked out) — go to login. - get_tree().change_scene_to_file("res://scenes/login/LoginScreen.tscn") - - func _on_logout_pressed() -> void: Auth.logout() get_tree().change_scene_to_file("res://scenes/login/LoginScreen.tscn")