Files
tiennm99 616f133989 feat: add gated admin console for api_keys registry (list/search/filter/revoke/mint)
- env-allowlist authz via ADMIN_GITHUB_USER_IDS on numeric provider_id (no migration)
- server-side re-gated revoke + manual-mint actions
- parameterized search/filter/paginate queries
- shared mint-key extraction (DRY) from generate-key
- notFound() for non-admins (404 never leaks route existence)
- 3 unit-test suites (authz/queries/integration)
2026-06-13 21:16:57 +07:00

28 lines
1.0 KiB
JavaScript

import "server-only";
import { getCurrentGithubIdentity } from "@/lib/auth/current-github-identity";
import { isAdmin, parseAdminIds } from "@/lib/auth/admin-allowlist";
// Re-export the pure helpers so server code has a single import surface while
// the unit tests import them from `admin-allowlist.js` (no `server-only` guard).
export { isAdmin, parseAdminIds };
/**
* Resolve the current GitHub identity and gate it in one call — the single gate
* used by the `/admin` page and every admin server action.
*
* `getCurrentGithubIdentity()` returns `null` when unauthenticated and can throw
* on malformed session metadata; both map to "not admin".
*
* @returns {Promise<import('./current-github-identity').GithubIdentity|null>}
* the identity when admin, else `null` (caller maps to `notFound()`/rejection).
*/
export async function requireAdminIdentity() {
try {
const identity = await getCurrentGithubIdentity();
return identity && isAdmin(identity) ? identity : null;
} catch {
return null;
}
}