From 3e6b0704afb8e9dc6823744dd34cc5eb5a36a78f Mon Sep 17 00:00:00 2001 From: syui Date: Fri, 3 Apr 2026 15:58:42 +0900 Subject: [PATCH] fix pds r --- src/commands/pds.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/commands/pds.rs b/src/commands/pds.rs index 5a3a2a8..6371f15 100644 --- a/src/commands/pds.rs +++ b/src/commands/pds.rs @@ -105,6 +105,15 @@ pub fn show_session(is_bot: bool) -> Result<()> { /// Refresh access token pub async fn refresh(is_bot: bool) -> Result<()> { use super::auth; + use super::oauth; + + // Check state before refresh + let had_oauth = oauth::has_oauth_session(is_bot); + let old_token = if had_oauth { + oauth::load_oauth_session(is_bot).ok().map(|s| s.access_token.clone()) + } else { + None + }; let session = if is_bot { auth::refresh_bot_session().await? @@ -112,13 +121,23 @@ pub async fn refresh(is_bot: bool) -> Result<()> { auth::refresh_session().await? }; - let has_oauth = super::oauth::has_oauth_session(is_bot); + // Determine what happened + let has_oauth_now = oauth::has_oauth_session(is_bot); + let action = if had_oauth && has_oauth_now { + let new_token = oauth::load_oauth_session(is_bot).ok().map(|s| s.access_token.clone()); + if old_token == new_token { "token_valid" } else { "token_refreshed" } + } else if had_oauth && !has_oauth_now { + "oauth_failed_legacy_fallback" + } else { + "legacy_refreshed" + }; + let info = serde_json::json!({ "did": session.did, "handle": session.handle, "pds": session.pds.as_deref().unwrap_or("bsky.social"), - "auth": if has_oauth { "oauth" } else { "legacy" }, - "refreshed": true, + "auth": if has_oauth_now { "oauth" } else { "legacy" }, + "status": action, }); println!("{}", serde_json::to_string_pretty(&info)?); Ok(())