Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 15 additions & 3 deletions src-tauri/src/commands/auth_login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,13 @@ pub async fn auth_login(
.expect("Client no build");

// 等待 deep link 回调传回 code/state
let callback = rx
.await
.map_err(|_| anyhow::anyhow!("auth flow cancelled or timed out"))?;
let callback = match rx.await {
Ok(callback) => callback,
Err(_) => {
log::info!("auth flow cancelled");
return Ok(());
}
};

// 防止 CSRF
if let Some(state) = callback.state.as_ref() {
Expand Down Expand Up @@ -282,6 +286,14 @@ pub async fn auth_login(
fut.await.map_err(|e| e.to_string())
}

#[tauri::command]
pub fn auth_cancel(flow_state: State<'_, AuthFlowState>) -> Result<(), String> {
if let Ok(mut guard) = flow_state.pending.lock() {
let _ = guard.take();
}
Ok(())
}

/// 确保 access_token 新鲜;如过期则用 refresh_token 刷新并更新存储
pub async fn ensure_fresh_token(
_app: &AppHandle,
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::setup::apply_window_effects;
use crate::setup::menu::{build_menu, handle_menu_event};
use crate::setup::setup_tray;

use crate::commands::auth_login::{auth_login, handle_auth_callback, AuthFlowState};
use crate::commands::auth_login::{auth_cancel, auth_login, handle_auth_callback, AuthFlowState};
use crate::commands::get_asset_detail::get_asset_detail;
use crate::commands::get_assets::get_assets;
use crate::commands::get_config::get_config;
Expand Down Expand Up @@ -153,6 +153,7 @@ pub fn run() {
pull_up,
unfavorite,
auth_login,
auth_cancel,
get_assets,
get_config,
get_setting,
Expand Down
8 changes: 7 additions & 1 deletion ui/components/SideBar/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,13 @@ onBeforeUnmount(() => {
</div>
</UDropdownMenu>

<UButton v-else variant="subtle" icon="line-md:log-in" class="w-full mb-2" @click="openLoginPage">
<UButton
v-else
variant="subtle"
icon="line-md:log-in"
class="w-full mb-2"
@click="openLoginPage"
>
<span v-if="!props.collapse">
{{ t("Common.Login") }}
</span>
Expand Down
13 changes: 10 additions & 3 deletions ui/pages/auth/browser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const headingClass = computed(() => (userTheme.value === "dark" ? "text-gray-50"
const subTextClass = computed(() => (userTheme.value === "dark" ? "text-gray-300" : "text-gray-600"));

const back = () => {
void useTauriCoreInvoke("auth_cancel", {}).catch((error) => {
console.debug("auth_cancel failed:", error);
});

navigateTo({
path: localePath({ path: "/" })
});
Expand Down Expand Up @@ -76,8 +80,8 @@ onMounted(async () => {
});

unlistenLoginSuccessRef.value = await useTauriEventListen("login-success-detected", async (event) => {
const { status, profile, bearer, current_org, resolved_site, permission_orgs, xpack_license_valid }
= event.payload as UserIntiInfo & { bearer: string };
const { status, profile, bearer, current_org, resolved_site, permission_orgs, xpack_license_valid } =
event.payload as UserIntiInfo & { bearer: string };

const profileData = JSON.parse((profile as any).data);
const currentOrgData = JSON.parse((current_org as any).data);
Expand Down Expand Up @@ -123,14 +127,17 @@ onMounted(async () => {
onBeforeUnmount(() => {
if (unlistenAuth.value) unlistenAuth.value();
if (unlistenLoginSuccessRef.value) unlistenLoginSuccessRef.value();
void useTauriCoreInvoke("auth_cancel", {}).catch((error) => {
console.debug("auth_cancel failed:", error);
});
});
</script>

<template>
<div class="flex flex-col items-center justify-center px-6 py-10 h-full">
<div class="flex flex-col items-center gap-6 rounded-3xl px-8 py-10 w-full max-w-xl border" :class="cardBgClass">
<div class="flex flex-col items-center gap-3">
<img src="/logo.png" alt="logo" class="w-16 h-16 rounded-2xl">
<img src="/logo.png" alt="logo" class="w-16 h-16 rounded-2xl" />
</div>

<section class="text-center space-y-4 w-full">
Expand Down