fixed
This commit is contained in:
23
src/App.jsx
23
src/App.jsx
@@ -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 />} />
|
||||
|
||||
Reference in New Issue
Block a user