mirror of
https://github.com/tiennm99/llmapikey.git
synced 2026-06-17 08:52:35 +00:00
616f133989
- 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)
28 lines
1.0 KiB
JavaScript
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;
|
|
}
|
|
}
|