2
0

fix pds r

This commit is contained in:
2026-04-03 15:58:42 +09:00
parent 1a4bf0e1ba
commit 3e6b0704af

View File

@@ -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(())