fix many request issue
Build & Push / Pipeline Tests (push) Successful in 1m53s
Test / Type Check (all packages) (push) Successful in 54s
Build & Push / Build & Push Docker Image (push) Successful in 3m43s
Test / API Unit Tests (push) Successful in 1m15s
Test / Homepage Unit Tests (push) Successful in 47s
Test / Carplace Unit Tests (push) Successful in 42s
Test / Admin Unit Tests (push) Successful in 43s
Test / Dashboard Unit Tests (push) Successful in 43s
Test / API Integration Tests (push) Successful in 1m10s
Build & Push / Pipeline Tests (push) Successful in 1m53s
Test / Type Check (all packages) (push) Successful in 54s
Build & Push / Build & Push Docker Image (push) Successful in 3m43s
Test / API Unit Tests (push) Successful in 1m15s
Test / Homepage Unit Tests (push) Successful in 47s
Test / Carplace Unit Tests (push) Successful in 42s
Test / Admin Unit Tests (push) Successful in 43s
Test / Dashboard Unit Tests (push) Successful in 43s
Test / API Integration Tests (push) Successful in 1m10s
This commit is contained in:
@@ -41,12 +41,21 @@ export default function AdminDashboardLayout({ children }: { children: React.Rea
|
|||||||
const [ready, setReady] = useState(false)
|
const [ready, setReady] = useState(false)
|
||||||
const [admin, setAdmin] = useState<AdminSessionUser | null>(null)
|
const [admin, setAdmin] = useState<AdminSessionUser | null>(null)
|
||||||
const [unreadNotifications, setUnreadNotifications] = useState(0)
|
const [unreadNotifications, setUnreadNotifications] = useState(0)
|
||||||
|
const redirectingToLogin = useRef(false)
|
||||||
|
|
||||||
|
function redirectToLogin() {
|
||||||
|
if (redirectingToLogin.current) return
|
||||||
|
redirectingToLogin.current = true
|
||||||
|
window.location.replace(buildUnifiedLoginUrl(pathname))
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false
|
let cancelled = false
|
||||||
|
const controller = new AbortController()
|
||||||
|
|
||||||
fetch(`${ADMIN_API_BASE}/admin/auth/me`, {
|
fetch(`${ADMIN_API_BASE}/admin/auth/me`, {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
signal: controller.signal,
|
||||||
})
|
})
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
if (cancelled) return
|
if (cancelled) return
|
||||||
@@ -54,7 +63,7 @@ export default function AdminDashboardLayout({ children }: { children: React.Rea
|
|||||||
const json = await response.json().catch(() => null)
|
const json = await response.json().catch(() => null)
|
||||||
const resolvedAdmin = (json?.data ?? json) as AdminSessionUser | null
|
const resolvedAdmin = (json?.data ?? json) as AdminSessionUser | null
|
||||||
if (!resolvedAdmin?.id || !resolvedAdmin?.email || !resolvedAdmin?.role) {
|
if (!resolvedAdmin?.id || !resolvedAdmin?.email || !resolvedAdmin?.role) {
|
||||||
window.location.replace(buildUnifiedLoginUrl(pathname))
|
redirectToLogin()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setAdmin(resolvedAdmin)
|
setAdmin(resolvedAdmin)
|
||||||
@@ -68,15 +77,17 @@ export default function AdminDashboardLayout({ children }: { children: React.Rea
|
|||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
window.location.replace(buildUnifiedLoginUrl(pathname))
|
redirectToLogin()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((err) => {
|
||||||
if (!cancelled) window.location.replace(buildUnifiedLoginUrl(pathname))
|
if (err?.name === 'AbortError') return
|
||||||
|
if (!cancelled) redirectToLogin()
|
||||||
})
|
})
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true
|
cancelled = true
|
||||||
|
controller.abort()
|
||||||
}
|
}
|
||||||
}, [pathname])
|
}, [pathname])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user