Fix 401: force logout si token expiré (Dashboard)
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user