mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-24 02:39:19 -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 { useTranslation } from 'react-i18next';
|
||||||
import { ApiResponse, BearerKey } from '@/types';
|
import { ApiResponse, BearerKey } from '@/types';
|
||||||
import { useToast } from '@/contexts/ToastContext';
|
import { useToast } from '@/contexts/ToastContext';
|
||||||
|
import { useAuth } from '@/contexts/AuthContext';
|
||||||
import { apiGet, apiPut, apiPost, apiDelete } from '@/utils/fetchInterceptor';
|
import { apiGet, apiPut, apiPost, apiDelete } from '@/utils/fetchInterceptor';
|
||||||
|
|
||||||
// Define types for the settings data
|
// Define types for the settings data
|
||||||
@@ -153,6 +154,7 @@ interface SettingsProviderProps {
|
|||||||
export const SettingsProvider: React.FC<SettingsProviderProps> = ({ children }) => {
|
export const SettingsProvider: React.FC<SettingsProviderProps> = ({ children }) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { showToast } = useToast();
|
const { showToast } = useToast();
|
||||||
|
const { auth } = useAuth();
|
||||||
|
|
||||||
const [routingConfig, setRoutingConfig] = useState<RoutingConfig>({
|
const [routingConfig, setRoutingConfig] = useState<RoutingConfig>({
|
||||||
enableGlobalRoute: true,
|
enableGlobalRoute: true,
|
||||||
@@ -746,6 +748,15 @@ export const SettingsProvider: React.FC<SettingsProviderProps> = ({ children })
|
|||||||
fetchSettings();
|
fetchSettings();
|
||||||
}, [fetchSettings, refreshKey]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
if (routingConfig) {
|
if (routingConfig) {
|
||||||
setTempRoutingConfig({
|
setTempRoutingConfig({
|
||||||
|
|||||||
Reference in New Issue
Block a user