mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 00:55:25 +00:00
fix: mc account logout on stale (#6986)
This commit is contained in:
@@ -1038,6 +1038,7 @@ async function checkUserChanges() {
|
|||||||
try {
|
try {
|
||||||
const defaultId = await get_default_user()
|
const defaultId = await get_default_user()
|
||||||
if (defaultId !== currentUserId.value) {
|
if (defaultId !== currentUserId.value) {
|
||||||
|
await accountsCard.value?.refreshValues()
|
||||||
await loadCurrentUser()
|
await loadCurrentUser()
|
||||||
await loadCapes()
|
await loadCapes()
|
||||||
await loadSkins()
|
await loadSkins()
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ pub async fn finish_login(
|
|||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn get_default_user() -> crate::Result<Option<uuid::Uuid>> {
|
pub async fn get_default_user() -> crate::Result<Option<uuid::Uuid>> {
|
||||||
let state = State::get().await?;
|
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))
|
Ok(user.map(|user| user.offline_profile.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,26 @@ pub enum MinecraftAuthenticationError {
|
|||||||
NoUserHash,
|
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)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct MinecraftLoginFlow {
|
pub struct MinecraftLoginFlow {
|
||||||
pub verifier: String,
|
pub verifier: String,
|
||||||
@@ -466,6 +486,23 @@ impl Credentials {
|
|||||||
return Ok(Some(creds));
|
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)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user