client: fix auth_failed loop — logout + navigate from Auth.gd centrally

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 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-01 10:57:15 -05:00
co-authored by Claude Happy
parent 3d2b9c3608
commit 2643fe4276
2 changed files with 12 additions and 19 deletions
@@ -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")