fix(console): fix stuck authentication check and add reliable redirect to /console/login

- Add immediate redirection to /console/login when unauthenticated in AdminLayout
- Add timeout (4000ms) with AbortController in adminApi.ts to prevent infinite pending fetch
- Provide explicit sign-in link in layout fallback view
This commit is contained in:
2026-08-25 14:42:26 +09:00
parent 9bdc9bdd9a
commit 54fe425b3c
2 changed files with 55 additions and 26 deletions
+24 -15
View File
@@ -153,23 +153,32 @@ async function request<T>(
const baseUrl = getAdminApiBaseUrl();
const url = `${baseUrl}${endpoint}`;
const response = await fetch(url, {
...options,
headers,
cache: "no-store",
});
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 4000);
if (response.status === 204) {
return {} as T;
try {
const response = await fetch(url, {
...options,
headers,
signal: controller.signal,
cache: "no-store",
});
if (response.status === 204) {
return {} as T;
}
const json = await response.json().catch(() => ({}));
if (!response.ok) {
const errorMsg = json?.error?.message || `Request failed with status ${response.status}`;
throw new Error(errorMsg);
}
return json.data;
} finally {
clearTimeout(timeoutId);
}
const json = await response.json().catch(() => ({}));
if (!response.ok) {
const errorMsg = json?.error?.message || `Request failed with status ${response.status}`;
throw new Error(errorMsg);
}
return json.data;
}
// 0. Auth Verification