fix pds r
This commit is contained in:
@@ -105,6 +105,15 @@ pub fn show_session(is_bot: bool) -> Result<()> {
|
|||||||
/// Refresh access token
|
/// Refresh access token
|
||||||
pub async fn refresh(is_bot: bool) -> Result<()> {
|
pub async fn refresh(is_bot: bool) -> Result<()> {
|
||||||
use super::auth;
|
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 {
|
let session = if is_bot {
|
||||||
auth::refresh_bot_session().await?
|
auth::refresh_bot_session().await?
|
||||||
@@ -112,13 +121,23 @@ pub async fn refresh(is_bot: bool) -> Result<()> {
|
|||||||
auth::refresh_session().await?
|
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!({
|
let info = serde_json::json!({
|
||||||
"did": session.did,
|
"did": session.did,
|
||||||
"handle": session.handle,
|
"handle": session.handle,
|
||||||
"pds": session.pds.as_deref().unwrap_or("bsky.social"),
|
"pds": session.pds.as_deref().unwrap_or("bsky.social"),
|
||||||
"auth": if has_oauth { "oauth" } else { "legacy" },
|
"auth": if has_oauth_now { "oauth" } else { "legacy" },
|
||||||
"refreshed": true,
|
"status": action,
|
||||||
});
|
});
|
||||||
println!("{}", serde_json::to_string_pretty(&info)?);
|
println!("{}", serde_json::to_string_pretty(&info)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user