mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-23 18:29:21 -05:00
feat: add authentication status listener to refresh settings on user login (#518)
This commit is contained in:
@@ -9,6 +9,7 @@ import React, {
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ApiResponse, BearerKey } from '@/types';
|
||||
import { useToast } from '@/contexts/ToastContext';
|
||||
import { useAuth } from '@/contexts/AuthContext';
|
||||
import { apiGet, apiPut, apiPost, apiDelete } from '@/utils/fetchInterceptor';
|
||||
|
||||
// Define types for the settings data
|
||||
@@ -153,6 +154,7 @@ interface SettingsProviderProps {
|
||||
export const SettingsProvider: React.FC<SettingsProviderProps> = ({ children }) => {
|
||||
const { t } = useTranslation();
|
||||
const { showToast } = useToast();
|
||||
const { auth } = useAuth();
|
||||
|
||||
const [routingConfig, setRoutingConfig] = useState<RoutingConfig>({
|
||||
enableGlobalRoute: true,
|
||||
@@ -746,6 +748,15 @@ export const SettingsProvider: React.FC<SettingsProviderProps> = ({ children })
|
||||
fetchSettings();
|
||||
}, [fetchSettings, refreshKey]);
|
||||
|
||||
// Watch for authentication status changes - refetch settings after login
|
||||
useEffect(() => {
|
||||
if (auth.isAuthenticated) {
|
||||
console.log('[SettingsContext] User authenticated, triggering settings refresh');
|
||||
// When user logs in, trigger a refresh to load settings
|
||||
triggerRefresh();
|
||||
}
|
||||
}, [auth.isAuthenticated, triggerRefresh]);
|
||||
|
||||
useEffect(() => {
|
||||
if (routingConfig) {
|
||||
setTempRoutingConfig({
|
||||
|
||||
Reference in New Issue
Block a user