feat: 添加用户认证服务和全局设置管理上下文
This commit is contained in:
@@ -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<string | null>(null);
|
||||
|
||||
const fetchSettings = useCallback(async () => {
|
||||
if (!isAuthenticated()) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const data = await getSettings();
|
||||
setSettings(data);
|
||||
|
||||
@@ -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('/')) {
|
||||
|
||||
Reference in New Issue
Block a user