feat: add in-app admin navigation for whitelisted users

Detect admin access after login and expose a header button that opens /admin via client-side routing so the session stays unlocked when returning to the app.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-05 10:03:46 +02:00
parent e1cb2754c4
commit 43cf589613
9 changed files with 79 additions and 9 deletions
+14 -1
View File
@@ -1,4 +1,4 @@
import { apiJson } from './api.js'
import { ApiError, apiJson } from './api.js'
const ADMIN_BASE = '/api/admin'
@@ -40,6 +40,19 @@ export async function fetchAdminMe(): Promise<AdminMe> {
return await apiJson<AdminMe>(`${ADMIN_BASE}/me`)
}
/** Returns true only for users listed in server ADMIN_USER_IDS. */
export async function checkAdminAccess(): Promise<boolean> {
try {
await fetchAdminMe()
return true
} catch (err) {
if (err instanceof ApiError && (err.status === 401 || err.status === 403)) {
return false
}
return false
}
}
export async function fetchAdminSummary(): Promise<AdminSummary> {
return await apiJson<AdminSummary>(`${ADMIN_BASE}/summary`)
}