Persist login cookies for seamless password login restart
All checks were successful
Build plugin / build (push) Successful in 1m8s

This commit is contained in:
Jose Falanga 2026-08-17 02:04:00 -03:00
parent e2a4464d0d
commit 2b07195789
3 changed files with 112 additions and 15 deletions

View file

@ -18,6 +18,7 @@ var itch: ItchClient
var api_key := settings_manager.get_value("plugin.itch", "api_key", "") as String
var login_method := settings_manager.get_value("plugin.itch", "login_method", 0) as int
var username := settings_manager.get_value("plugin.itch", "username", "") as String
var saved_cookie := settings_manager.get_value("plugin.itch", "cookie", "") as String
func _ready() -> void:
@ -29,6 +30,7 @@ func _ready() -> void:
itch.bootstrap_finished.connect(_on_client_start)
itch.client_ready.connect(_on_client_ready)
itch.logged_in.connect(_on_client_logged_in)
itch.login_cookies_saved.connect(_on_cookies_saved)
add_child(itch)
# Load the Library implementation
@ -58,19 +60,20 @@ func _on_client_ready() -> void:
return
itch.login_with_api_key(api_key)
else:
# Username/password login
# Username/password login — try saved cookie first.
if username == "":
var notify := Notification.new("itch.io username required")
notify.icon = icon
logger.info(notify.text)
notification_manager.show(notify)
return
# Password is not persisted; prompt via settings if needed.
# For now, just log the message — the user must save from settings.
var notify := Notification.new("itch.io: open plugin settings to log in with username/password")
notify.icon = icon
logger.info(notify.text)
notification_manager.show(notify)
if saved_cookie != "":
itch.login_with_cookie(saved_cookie)
else:
var notify := Notification.new("itch.io: open plugin settings to log in")
notify.icon = icon
logger.info(notify.text)
notification_manager.show(notify)
# Triggers when the itch client finishes a login attempt
@ -79,17 +82,22 @@ func _on_client_logged_in(status: ItchClient.LOGIN_STATUS, profile: Dictionary)
notify.icon = icon
if status == ItchClient.LOGIN_STATUS.OK:
var username: String = profile.get("user", {}).get("username", "")
notify.text = "Successfully logged in to itch.io as " + username
var uname: String = profile.get("user", {}).get("username", "")
notify.text = "Successfully logged in to itch.io as " + uname
logger.info(notify.text)
notification_manager.show(notify)
return
notify.text = "Failed to log in to itch.io. Check your API key in plugin settings."
notify.text = "Failed to log in to itch.io. Check your credentials in plugin settings."
logger.warn(notify.text)
notification_manager.show(notify)
func _on_cookies_saved(uname: String, cookie: String) -> void:
settings_manager.set_value("plugin.itch", "username", uname)
settings_manager.set_value("plugin.itch", "cookie", cookie)
# Return the settings menu scene
func get_settings_menu() -> Control:
return settings_menu.instantiate()