diff --git a/src/contexts/SettingsContext.tsx b/src/contexts/SettingsContext.tsx index d3f37ce..db9976d 100644 --- a/src/contexts/SettingsContext.tsx +++ b/src/contexts/SettingsContext.tsx @@ -2,6 +2,8 @@ import React, { createContext, useContext, useState, useEffect, useCallback } fr import type { UserSettings } from '../types'; import { getSettings, updateSettings as apiUpdateSettings } from '../services/settingsService'; +import { isAuthenticated } from '../services/authService'; + interface SettingsContextType { settings: UserSettings | null; loading: boolean; @@ -18,6 +20,10 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil const [error, setError] = useState(null); const fetchSettings = useCallback(async () => { + if (!isAuthenticated()) { + setLoading(false); + return; + } try { const data = await getSettings(); setSettings(data); diff --git a/src/services/authService.ts b/src/services/authService.ts index 655b519..7ea3369 100644 --- a/src/services/authService.ts +++ b/src/services/authService.ts @@ -140,7 +140,7 @@ export function getGitHubLoginUrl(state?: string): string { ? (import.meta.env.VITE_API_BASE_URL || 'http://localhost:2612/api/v1') : '/api/v1'; - console.log('[Auth] Generating GitHub URL with base:', baseUrl); + // 处理相对路径问题:URL构造函数依然需要完整的 base 才能处理相对路径 let fullUrlString; @@ -187,7 +187,7 @@ export function getGiteeLoginUrl(state?: string): string { ? (import.meta.env.VITE_API_BASE_URL || 'http://localhost:2612/api/v1') : '/api/v1'; - console.log('[Auth] Generating Gitee URL with base:', baseUrl); + let fullUrlString; if (baseUrl.startsWith('/')) {