You've already forked AstralRinth
forked from didirus/AstralRinth
feat(app): update profile every time token is refreshed (#2328)
Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com> Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
This commit is contained in:
@@ -178,19 +178,16 @@ pub async fn login_finish(
|
|||||||
|
|
||||||
minecraft_entitlements(&minecraft_token.access_token).await?;
|
minecraft_entitlements(&minecraft_token.access_token).await?;
|
||||||
|
|
||||||
let profile = minecraft_profile(&minecraft_token.access_token).await?;
|
let mut credentials = Credentials {
|
||||||
|
id: Uuid::default(),
|
||||||
let profile_id = profile.id.unwrap_or_default();
|
username: String::default(),
|
||||||
|
|
||||||
let credentials = Credentials {
|
|
||||||
id: profile_id,
|
|
||||||
username: profile.name,
|
|
||||||
access_token: minecraft_token.access_token,
|
access_token: minecraft_token.access_token,
|
||||||
refresh_token: oauth_token.value.refresh_token,
|
refresh_token: oauth_token.value.refresh_token,
|
||||||
expires: oauth_token.date
|
expires: oauth_token.date
|
||||||
+ Duration::seconds(oauth_token.value.expires_in as i64),
|
+ Duration::seconds(oauth_token.value.expires_in as i64),
|
||||||
active: true,
|
active: true,
|
||||||
};
|
};
|
||||||
|
credentials.get_profile().await?;
|
||||||
|
|
||||||
credentials.upsert(exec).await?;
|
credentials.upsert(exec).await?;
|
||||||
|
|
||||||
@@ -245,11 +242,22 @@ impl Credentials {
|
|||||||
self.expires = oauth_token.date
|
self.expires = oauth_token.date
|
||||||
+ Duration::seconds(oauth_token.value.expires_in as i64);
|
+ Duration::seconds(oauth_token.value.expires_in as i64);
|
||||||
|
|
||||||
|
self.get_profile().await?;
|
||||||
|
|
||||||
self.upsert(exec).await?;
|
self.upsert(exec).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_profile(&mut self) -> crate::Result<()> {
|
||||||
|
let profile = minecraft_profile(&self.access_token).await?;
|
||||||
|
|
||||||
|
self.id = profile.id.unwrap_or_default();
|
||||||
|
self.username = profile.name;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn get_default_credential(
|
pub async fn get_default_credential(
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite> + Copy,
|
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite> + Copy,
|
||||||
|
|||||||
Reference in New Issue
Block a user