From 640810c4df2124c9f8ca91c1b66b9445b4358dee Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Fri, 25 Apr 2025 23:30:22 +0800 Subject: [PATCH] update --- packages/frontend/src/stores/auth.store.ts | 32 +++++++++++++++---- .../frontend/src/stores/settings.store.ts | 9 ++++++ packages/frontend/src/views/LoginView.vue | 24 +++++++------- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/packages/frontend/src/stores/auth.store.ts b/packages/frontend/src/stores/auth.store.ts index e3e8771..02d0388 100644 --- a/packages/frontend/src/stores/auth.store.ts +++ b/packages/frontend/src/stores/auth.store.ts @@ -26,6 +26,16 @@ interface PublicCaptchaConfig { recaptchaSiteKey?: string; } +// Backend's full CAPTCHA Settings Interface (as returned by /settings/captcha) +interface FullCaptchaSettings { + enabled: boolean; + provider: 'hcaptcha' | 'recaptcha' | 'none'; + hcaptchaSiteKey?: string; + hcaptchaSecretKey?: string; // We won't use this in authStore + recaptchaSiteKey?: string; + recaptchaSecretKey?: string; // We won't use this in authStore +} + // Auth Store State 接口 interface AuthState { isAuthenticated: boolean; @@ -281,19 +291,29 @@ export const useAuthStore = defineStore('auth', { } }, - // NEW: 获取公共 CAPTCHA 配置 + // NEW: 获取公共 CAPTCHA 配置 (修改为从 /settings/captcha 获取) async fetchCaptchaConfig() { // Avoid refetching if already loaded if (this.publicCaptchaConfig !== null) return; // Don't set isLoading for this, it should be quick background fetch try { - console.log('[AuthStore] Fetching public CAPTCHA config...'); - const response = await apiClient.get('/auth/captcha/config'); - this.publicCaptchaConfig = response.data; - console.log('[AuthStore] Public CAPTCHA config loaded:', this.publicCaptchaConfig); + console.log('[AuthStore] Fetching CAPTCHA config from /settings/captcha...'); + // 修改 API 端点 + const response = await apiClient.get('/settings/captcha'); + const fullConfig = response.data; + + // 从完整配置中提取公共部分 + this.publicCaptchaConfig = { + enabled: fullConfig.enabled, + provider: fullConfig.provider, + hcaptchaSiteKey: fullConfig.hcaptchaSiteKey, + recaptchaSiteKey: fullConfig.recaptchaSiteKey, + }; + + console.log('[AuthStore] Public CAPTCHA config derived from /settings/captcha:', this.publicCaptchaConfig); } catch (error: any) { - console.error('获取公共 CAPTCHA 配置失败:', error.response?.data?.message || error.message); + console.error('获取 CAPTCHA 配置失败 (from /settings/captcha):', error.response?.data?.message || error.message); // Set a default disabled config on error to prevent blocking login UI this.publicCaptchaConfig = { enabled: false, diff --git a/packages/frontend/src/stores/settings.store.ts b/packages/frontend/src/stores/settings.store.ts index 396f5d1..88fdd21 100644 --- a/packages/frontend/src/stores/settings.store.ts +++ b/packages/frontend/src/stores/settings.store.ts @@ -3,6 +3,7 @@ import apiClient from '../utils/apiClient'; // 使用统一的 apiClient import { ref, computed } from 'vue'; // 移除 watch import i18n, { setLocale, defaultLng } from '../i18n'; // Import i18n instance and setLocale import type { PaneName } from './layout.store'; // +++ Import PaneName type +++ +import { useAuthStore } from './auth.store'; // <--- 导入 authStore // Import CAPTCHA types from backend (adjust path if needed, assuming types are mirrored or shared) // For now, let's assume they are available via a shared types definition or manually defined here // Assuming manual definition for now if no shared types exist: @@ -49,6 +50,8 @@ interface SettingsState { export const useSettingsStore = defineStore('settings', () => { + const authStore = useAuthStore(); // <--- 实例化 authStore + // --- State --- const settings = ref>({}); // 通用设置状态 const parsedSidebarPaneWidths = ref>({}); // NEW: 解析后的侧边栏宽度对象 @@ -428,6 +431,12 @@ export const useSettingsStore = defineStore('settings', () => { } console.log('[SettingsStore] CAPTCHA 设置更新成功。'); + // --- 新增:强制 authStore 重新获取配置 --- + console.log('[SettingsStore] Triggering authStore to refetch CAPTCHA config...'); + authStore.publicCaptchaConfig = null; // 重置 authStore 的状态以允许重新获取 + await authStore.fetchCaptchaConfig(); // 让 authStore 立即获取最新的配置 + // ----------------------------------------- + } catch (err: any) { console.error('更新 CAPTCHA 设置失败:', err); error.value = err.response?.data?.message || err.message || '更新 CAPTCHA 设置失败'; diff --git a/packages/frontend/src/views/LoginView.vue b/packages/frontend/src/views/LoginView.vue index e5065ec..ff4852a 100644 --- a/packages/frontend/src/views/LoginView.vue +++ b/packages/frontend/src/views/LoginView.vue @@ -1,5 +1,5 @@