Add session expiry renewal flow

This commit is contained in:
hz
2026-07-18 15:53:11 -05:00
parent 8c349314ad
commit a232e18c46
14 changed files with 575 additions and 21 deletions
+6 -2
View File
@@ -31,6 +31,7 @@ var pending_action := ""
var queue: Array = []
var text_scale := 1.0
var highlights := {}
var request_access_token := ""
func _ready() -> void:
@@ -148,11 +149,12 @@ func _send(action: String, method: int, suffix: String, payload: Dictionary = {}
if is_loading:
queue.append({"action": action, "method": method, "url": url, "payload": payload.duplicate(true)})
return
if AuthState.access_token.is_empty():
if not AuthState.can_send_authenticated_request():
return
is_loading = true
pending_action = action
var headers := PackedStringArray(["Authorization: Bearer %s" % AuthState.access_token])
request_access_token = AuthState.access_token
var headers := PackedStringArray(["Authorization: Bearer %s" % request_access_token])
var body := ""
if not payload.is_empty():
headers.append("Content-Type: application/json")
@@ -168,6 +170,8 @@ func _on_request_completed(result: int, response_code: int, _headers: PackedStri
pending_action = ""
is_loading = false
call_deferred("_process_queue")
if response_code == 401:
AuthState.handle_unauthorized(request_access_token)
if result != HTTPRequest.RESULT_SUCCESS or response_code < 200 or response_code >= 300:
var detail := body.get_string_from_utf8().strip_edges().left(240)
var message := "CCS request failed (%d). %s" % [response_code, detail]