Add session expiry renewal flow
This commit is contained in:
@@ -21,6 +21,7 @@ var history_next_cursor := ""
|
||||
var is_loading := false
|
||||
var pending_action := ""
|
||||
var request_queue: Array = []
|
||||
var request_access_token := ""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -122,14 +123,15 @@ func _send(action: String, method: int, suffix: String, payload: Dictionary = {}
|
||||
|
||||
|
||||
func _send_absolute(action: String, method: int, url: String, payload: Dictionary = {}) -> void:
|
||||
if AuthState.access_token == "":
|
||||
if not AuthState.can_send_authenticated_request():
|
||||
return
|
||||
if is_loading:
|
||||
request_queue.append({"action": action, "method": method, "url": url, "payload": payload.duplicate(true)})
|
||||
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")
|
||||
@@ -146,6 +148,8 @@ func _on_request_completed(result: int, response_code: int, _headers: PackedStri
|
||||
pending_action = ""
|
||||
is_loading = false
|
||||
call_deferred("_process_request_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 server_message := body.get_string_from_utf8().strip_edges()
|
||||
if server_message.length() > 240:
|
||||
|
||||
Reference in New Issue
Block a user