This commit is contained in:
2025-11-25 00:51:40 +05:30
parent 006ff2bce3
commit 46a70b6e8d
2 changed files with 27 additions and 7 deletions

View File

@@ -21,6 +21,7 @@ import Admin from './pages/Admin';
function App() {
const [user, setUser] = useState(null);
const [isAdmin, setIsAdmin] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const fetchProfile = async () => {
try {
@@ -29,8 +30,14 @@ function App() {
setIsAdmin(response.user.role === 'admin');
} catch (error) {
console.error('Failed to fetch profile:', error);
setUser(null);
setIsAdmin(false);
// Only logout on authentication errors (401/403), not network errors
if (error.response && (error.response.status === 401 || error.response.status === 403)) {
setUser(null);
setIsAdmin(false);
}
// For network errors, keep current state and try again later
} finally {
setIsLoading(false);
}
};
@@ -48,9 +55,19 @@ function App() {
setIsAdmin(false);
};
if (isLoading) {
return (
<div className="App">
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
<div>Loading...</div>
</div>
</div>
);
}
return (
<div className="App">
<Header user={user} onLogout={handleLogout} isAdmin={isAdmin} />
<Header user={user} onLogout={handleLogout} isAdmin={isLoading ? false : isAdmin} />
<main>
<Routes>
<Route path="/" element={<Home />} />