feat:移除了弹窗,服务器添加sls
This commit is contained in:
45
packages/app-lib/src/api/mr_auth.rs
Normal file
45
packages/app-lib/src/api/mr_auth.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use crate::state::ModrinthCredentials;
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn authenticate_begin_flow() -> &'static str {
|
||||
crate::state::get_login_url()
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn authenticate_finish_flow(
|
||||
code: &str,
|
||||
) -> crate::Result<ModrinthCredentials> {
|
||||
let state = crate::State::get().await?;
|
||||
|
||||
let creds = crate::state::finish_login_flow(
|
||||
code,
|
||||
&state.api_semaphore,
|
||||
&state.pool,
|
||||
)
|
||||
.await?;
|
||||
|
||||
creds.upsert(&state.pool).await?;
|
||||
Ok(creds)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn logout() -> crate::Result<()> {
|
||||
let state = crate::State::get().await?;
|
||||
let current = ModrinthCredentials::get_active(&state.pool).await?;
|
||||
|
||||
if let Some(current) = current {
|
||||
ModrinthCredentials::remove(¤t.user_id, &state.pool).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn get_credentials() -> crate::Result<Option<ModrinthCredentials>> {
|
||||
let state = crate::State::get().await?;
|
||||
let current =
|
||||
ModrinthCredentials::get_and_refresh(&state.pool, &state.api_semaphore)
|
||||
.await?;
|
||||
|
||||
Ok(current)
|
||||
}
|
||||
Reference in New Issue
Block a user