bug fixes

This commit is contained in:
Matthias Hochmeister
2026-03-03 11:45:08 +01:00
parent 3101f1a9c5
commit d91f757f34
12 changed files with 313 additions and 47 deletions

View File

@@ -37,17 +37,19 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
// Optionally verify token is still valid
try {
await authService.getCurrentUser();
} catch (error) {
} catch (error: any) {
console.error('Token validation failed:', error);
// Token is invalid, clear it
removeToken();
removeUser();
setState({
user: null,
token: null,
isAuthenticated: false,
isLoading: false,
});
// Only clear auth for explicit 401 Unauthorized
// Network errors or server errors (5xx) should not log out the user
if (error?.status === 401) {
removeToken();
removeUser();
setState({ user: null, token: null, isAuthenticated: false, isLoading: false });
} else {
// Keep existing auth state on non-auth errors (network issues, server down)
// The user may still be authenticated, just the server is temporarily unavailable
setState({ user, token, isAuthenticated: true, isLoading: false });
}
} finally {
setAuthInitialized(true);
}