permission-core Auth
This example shows how to connect permission-core to VextJS Auth. Vext keeps authentication and route guards separate:
auth()parses the Bearer token and fillsreq.auth.permission-coreowns authorization decisions such asinvoke + GET:/api/posts.- Each route keeps its final
RouteOptions.authinline or in a same-fileconst, so build indexing, runtime guards, and OpenAPI read the same contract.
1. Install
For a demo or test project, MemoryAdapter is enough. For production, follow permission-core's production guide and use a persistent storage adapter with the cache-hub + monsqlize stack recommended by permission-core.
2. Create the permission plugin
3. Bridge auth() to permission-core
Register the middleware name in src/config/default.ts:
4. Declare statically projectable route guards
The route index does not execute imported or local helper functions. Keep each final guard shape in the route file as a same-file const; this makes the complete middleware, permission, security, and docs contract visible before runtime:
Keep related route constants together in their route module. Shared runtime behavior remains centralized in the permission-core-auth middleware and permission provider; the route contract itself stays statically visible.
5. Protect routes with the final option constants
RouteOptions.auth remains the guard contract. Route-options helper calls are rejected by the finite static grammar; use an inline final object or a same-file final const. The older openapi.guardSecurityMap fallback still exists only for legacy middleware-only routes.
6. Direct assert() in handlers
Use req.auth.assert() only when a route has additional runtime decisions that are easier to express inside the handler:
If permission-core denies the operation, Vext returns AUTH_FORBIDDEN through the Auth guard path.
7. Verify
Verify this integration in your application's test suite after registering the middleware and routes. At minimum, assert:
- authentication fills the expected identity and a safe request context
- permission-core
can()allows an authorized operation and denies an unauthorized one - missing, malformed, and unknown credentials return the documented errors
req.auth.assert()returnsAUTH_FORBIDDENfor a denied operation and the OpenAPI document declaresbearerAuth