Skip to Content
API Reference

API Reference

Aegis Guard ships three entry points.

aegis-guard/core

Framework free: types, config, the pure engine, and the guard factory.

ExportDescription
initAegis(config)Initialize the library with your adapter and auth context
createGuard(config)Build a portable AegisGuard. The base for any framework binding
evaluatePermission(r, c, d)Pure decision engine. Explicit context and deps, no globals
createValidatedAdapterWrap an adapter so its returned data is validated
AegisAdapterInterface your database adapter must implement
AegisConfigConfiguration object type
AegisContextUser context type ({ userId, ...custom })
AegisResourceResource type ({ key, description? })
AegisGuard / BoundGuardThe universal guard surface and its per request binder
AegisDecisionExplainable result (allowed, reason, matched/missing roles)
GuardInputContext input union (omit, { request }, or AegisContext)
Validator<T>(data: unknown) => T. Runtime validator type
AegisError / AegisDeniedErrorTyped config error and denial error (.decision)
AegisValidationErrorThrown when a validator rejects (.source, .cause)

aegis-guard/server

Next.js specific. Re-exports the core guard functions plus Shield and handlers.

ExportDescription
<Shield>Async Server Component that gates content by permission
checkPermission(resource)Returns boolean. Use in API routes, middleware, tRPC
decidePermission(resource)Returns the full AegisDecision (allowed, reason, roles)
requirePermission(resource)Returns the decision, or throws AegisDeniedError on deny
createAegisHandler()Returns { GET, POST } handlers for the admin API
createAegisMiddleware(options)Returns a Next.js middleware that gates routes by permission

aegis-guard/client

React specific. Hooks and dashboard components.

ExportDescription
useAegisResources(options?)Hook to fetch resources with their roles
useUpdatePermissions(options?)Hook to update resource permissions
<AegisDashboard>Unstyled dashboard with semantic HTML. Bring your own CSS
<AegisDashboardStyled>Tailwind styled dashboard, ready to use

Adapter interface

interface AegisAdapter { getUserRoles(ctx: AegisContext): Promise<string[]>; getAllowedRoles(resourceKey: string): Promise<string[]>; getAllResources(): Promise<AegisResource[]>; setResourcePermissions(resourceKey: string, roles: string[]): Promise<void>; upsertResource(resourceKey: string, description?: string): Promise<void>; }

Dashboard props

PropTypeDefaultDescription
rolesstring[]requiredAll possible roles in your app
apiBasestring"/api/aegis"Base path for the admin API
classNamestringCSS class for the root element
titlestring"Aegis Permissions"Dashboard heading

Tailwind setup

If using <AegisDashboardStyled>, scan the library’s compiled classes.

Tailwind v4, add to your CSS:

@source "../../node_modules/aegis-guard/dist";

Tailwind v3, add to tailwind.config.js content:

"./node_modules/aegis-guard/dist/**/*.{js,mjs}",
Last updated on