Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): update Minecraft profile every time token is refreshed #2328

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions packages/app-lib/src/state/minecraft_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,16 @@ pub async fn login_finish(

minecraft_entitlements(&minecraft_token.access_token).await?;

let profile = minecraft_profile(&minecraft_token.access_token).await?;

let profile_id = profile.id.unwrap_or_default();

let credentials = Credentials {
id: profile_id,
username: profile.name,
let mut credentials = Credentials {
id: Uuid::default(),
username: String::default(),
access_token: minecraft_token.access_token,
refresh_token: oauth_token.value.refresh_token,
expires: oauth_token.date
+ Duration::seconds(oauth_token.value.expires_in as i64),
active: true,
};
credentials.get_profile().await?;

credentials.upsert(exec).await?;

Expand Down Expand Up @@ -245,11 +242,22 @@ impl Credentials {
self.expires = oauth_token.date
+ Duration::seconds(oauth_token.value.expires_in as i64);

self.get_profile().await?;

self.upsert(exec).await?;

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]
pub async fn get_default_credential(
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite> + Copy,
Expand Down