Fix React error #130 - Remove authentication race condition

- Remove setTimeout delays in AdminAuthContext login function
- Make authentication state updates synchronous
- Replace setTimeout navigation with state-based navigation in AdminLoginPage
- Add proper error handling and component lifecycle management in CreateEventPage
- Prevent navigation if component unmounts during async operations

This fixes the issue where users would see React error #130 during login
and couldn't create events or save settings.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-07-07 13:12:39 +02:00
parent 9dd643338b
commit 2e10374e2c
3 changed files with 40 additions and 26 deletions
+13 -10
View File
@@ -36,13 +36,19 @@ export const AdminAuthProvider: React.FC<AdminAuthProviderProps> = ({ children }
useEffect(() => {
// Check if user has a valid token on mount
const checkAuth = async () => {
const token = getAuthToken(true);
if (token) {
// For now, just assume the token is valid
// TODO: Validate token with backend and get user info
setIsAuthenticated(true);
try {
const token = getAuthToken(true);
if (token) {
// For now, just assume the token is valid
// TODO: Validate token with backend and get user info
setIsAuthenticated(true);
}
} catch (error) {
console.error('Auth check error:', error);
setError('Failed to check authentication');
} finally {
setIsLoading(false);
}
setIsLoading(false);
};
checkAuth();
@@ -52,10 +58,7 @@ export const AdminAuthProvider: React.FC<AdminAuthProviderProps> = ({ children }
// Token is already stored in cookie by authService
setUser(user);
setError(null);
// Small delay to ensure state is properly updated
setTimeout(() => {
setIsAuthenticated(true);
}, 100);
setIsAuthenticated(true);
};
const logout = () => {