Files
picpeak/frontend/src/hooks/useSessionTimeout.ts
T
paul d594d00227 Fix brand theme application and add comprehensive translations
- Fixed theme not being reflected on gallery and admin login pages
- Created GlobalThemeProvider to apply themes globally
- Updated gallery and admin login pages to use dynamic CSS variables
- Added complete translations for all admin sections in English and German:
  - Notifications management
  - Event view and creation
  - Photo upload functionality
  - Category management
  - Archive page view
  - Analytics dashboard
  - Branding and theme settings
  - System settings
  - CMS page management
  - Email configuration
- Fixed admin photo management display issues
- Fixed photo upload category assignment
- Added password reset functionality for galleries
- Improved error handling and user feedback

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-08 17:07:40 +02:00

40 lines
1.2 KiB
TypeScript

import { useEffect, useCallback } from 'react';
import { useAdminAuth } from '../contexts';
import { api } from '../config/api';
// Hook to handle session timeout
export const useSessionTimeout = () => {
const { logout } = useAdminAuth();
const handleSessionTimeout = useCallback((error: any) => {
if (error?.response?.data?.code === 'SESSION_TIMEOUT') {
// Clear local auth state
logout();
// Redirect to login with message
window.location.href = '/admin/login?session=expired';
return true;
}
return false;
}, [logout]);
useEffect(() => {
// Add response interceptor to handle session timeout
const interceptor = api.interceptors.response.use(
response => response,
error => {
if (handleSessionTimeout(error)) {
// Don't propagate the error if it was a session timeout
return Promise.reject(new Error('Session expired'));
}
return Promise.reject(error);
}
);
// Clean up interceptor on unmount
return () => {
api.interceptors.response.eject(interceptor);
};
}, [handleSessionTimeout]);
return { handleSessionTimeout };
};