Fix 401: force logout si token expiré (Dashboard)

This commit is contained in:
2026-09-02 09:43:33 +00:00
parent 2d393e88a4
commit d21b1a5f51
2 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ function App() {
<BrowserRouter>
<Layout user={user} onLogout={handleLogout}>
<Routes>
<Route path='/' element={<Dashboard token={token} user={user} />} />
<Route path='/' element={<Dashboard token={token} user={user} onLogout={handleLogout} />} />
<Route path='*' element={<Navigate to='/' />} />
</Routes>
</Layout>
+7 -2
View File
@@ -14,7 +14,7 @@ function getCosts(d) {
return { nbUsers, doms, ksuite, site, extra, domCost, total: ksuite + site + extra + domCost }
}
export default function Dashboard({ token, user }) {
export default function Dashboard({ token, user, onLogout }) {
const [domains, setDomains] = useState([])
const [activeTab, setActiveTab] = useState(-1)
const [loading, setLoading] = useState(true)
@@ -23,7 +23,12 @@ export default function Dashboard({ token, user }) {
useEffect(() => {
fetch('/api/domains', { headers: { Authorization: 'Bearer ' + token } })
.then(r => r.json()).then(d => {
.then(r => {
if (r.status === 401) { onLogout && onLogout(); return null }
return r.json()
})
.then(d => {
if (!d) return
const all = d.parent ? [d.parent, ...d.children] : d.children
setDomains(all)
setLoading(false)