You've already forked AstralRinth
forked from didirus/AstralRinth
Initial bug fixes (#127)
* Initial bug fixes * fix compile error on non-mac * Fix even more bugs * Fix more * fix more * fix build * fix build * address review comments
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::{launcher::auth as inner, State};
|
||||
use futures::prelude::*;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
use crate::state::AuthTask;
|
||||
pub use inner::Credentials;
|
||||
|
||||
/// Authenticate a user with Hydra - part 1
|
||||
@@ -11,8 +12,7 @@ pub use inner::Credentials;
|
||||
/// to call authenticate and call the flow from the frontend.
|
||||
/// Visit the URL in a browser, then call and await 'authenticate_await_complete_flow'.
|
||||
pub async fn authenticate_begin_flow() -> crate::Result<url::Url> {
|
||||
let st = State::get().await?.clone();
|
||||
let url = st.auth_flow.write().await.begin_auth().await?;
|
||||
let url = AuthTask::begin_auth().await?;
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
@@ -21,12 +21,15 @@ pub async fn authenticate_begin_flow() -> crate::Result<url::Url> {
|
||||
/// This can be used in conjunction with 'authenticate_begin_flow'
|
||||
/// to call authenticate and call the flow from the frontend.
|
||||
pub async fn authenticate_await_complete_flow() -> crate::Result<Credentials> {
|
||||
let st = State::get().await?.clone();
|
||||
let credentials =
|
||||
st.auth_flow.write().await.await_auth_completion().await?;
|
||||
let credentials = AuthTask::await_auth_completion().await?;
|
||||
Ok(credentials)
|
||||
}
|
||||
|
||||
/// Cancels the active authentication flow
|
||||
pub async fn cancel_flow() -> crate::Result<()> {
|
||||
AuthTask::cancel().await
|
||||
}
|
||||
|
||||
/// Authenticate a user with Hydra
|
||||
/// To run this, you need to first spawn this function as a task, then
|
||||
/// open a browser to the given URL and finally wait on the spawned future
|
||||
@@ -38,7 +41,6 @@ pub async fn authenticate(
|
||||
) -> crate::Result<Credentials> {
|
||||
let mut flow = inner::HydraAuthFlow::new().await?;
|
||||
let state = State::get().await?;
|
||||
let mut users = state.users.write().await;
|
||||
|
||||
let url = flow.prepare_login_url().await?;
|
||||
browser_url.send(url).map_err(|url| {
|
||||
@@ -48,7 +50,10 @@ pub async fn authenticate(
|
||||
})?;
|
||||
|
||||
let credentials = flow.extract_credentials(&state.fetch_semaphore).await?;
|
||||
users.insert(&credentials).await?;
|
||||
{
|
||||
let mut users = state.users.write().await;
|
||||
users.insert(&credentials).await?;
|
||||
}
|
||||
|
||||
if state.settings.read().await.default_user.is_none() {
|
||||
let mut settings = state.settings.write().await;
|
||||
@@ -69,7 +74,7 @@ pub async fn refresh(user: uuid::Uuid) -> crate::Result<Credentials> {
|
||||
let fetch_semaphore = &state.fetch_semaphore;
|
||||
futures::future::ready(users.get(user).ok_or_else(|| {
|
||||
crate::ErrorKind::OtherError(format!(
|
||||
"Tried to refresh nonexistent user with ID {user}"
|
||||
"You are not logged in with a Minecraft account!"
|
||||
))
|
||||
.as_error()
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user