fix: mc account logout on stale (#6986)

This commit is contained in:
Calum H.
2026-08-04 14:29:03 +00:00
committed by GitHub
parent 6715a9c679
commit cfea3aba34
3 changed files with 39 additions and 1 deletions
+1
View File
@@ -1038,6 +1038,7 @@ async function checkUserChanges() {
try {
const defaultId = await get_default_user()
if (defaultId !== currentUserId.value) {
await accountsCard.value?.refreshValues()
await loadCurrentUser()
await loadCapes()
await loadSkins()
+1 -1
View File
@@ -39,7 +39,7 @@ pub async fn finish_login(
#[tracing::instrument]
pub async fn get_default_user() -> crate::Result<Option<uuid::Uuid>> {
let state = State::get().await?;
let user = Credentials::get_active(&state.pool).await?;
let user = Credentials::get_default_credential(&state.pool).await?;
Ok(user.map(|user| user.offline_profile.id))
}
@@ -79,6 +79,26 @@ pub enum MinecraftAuthenticationError {
NoUserHash,
}
#[derive(Deserialize)]
struct OAuthErrorResponse {
error: String,
}
impl MinecraftAuthenticationError {
fn is_invalid_grant(&self) -> bool {
matches!(
self,
Self::DeserializeResponse {
step: MinecraftAuthStep::RefreshOAuthToken,
raw,
status_code: StatusCode::BAD_REQUEST,
..
} if serde_json::from_str::<OAuthErrorResponse>(raw)
.is_ok_and(|response| response.error == "invalid_grant")
)
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct MinecraftLoginFlow {
pub verifier: String,
@@ -466,6 +486,23 @@ impl Credentials {
return Ok(Some(creds));
}
if matches!(
&*err.raw,
ErrorKind::MinecraftAuthenticationError(source)
if source.is_invalid_grant()
) {
Self::remove(creds.offline_profile.id, exec).await?;
if let Some((_, mut user)) =
Self::get_all(exec).await?.into_iter().next()
{
user.active = true;
user.upsert(exec).await?;
}
return Ok(None);
}
Err(err)
}
}