Skip to content

covenix / Security

Function: Security()

Security(scheme, scopes?): ClassDecorator & MethodDecorator

Defined in: src/decorators.ts:299

Declares a security requirement for the operation, matching a named scheme in the Covenix instance's security map. Before the handler runs, covenix invokes that scheme's handler; on success the principal is available via @Principal().

Usable on a method or on the controller class (applies to every route that doesn't declare its own). Stackable — multiple @Security decorators are alternatives (OR): the request is allowed if any one is satisfied.

Parameters

scheme

string

The security scheme name (a key in new Covenix({ security })).

scopes?

string[] = []

Scopes the route requires for this scheme (passed to the handler).

Returns

ClassDecorator & MethodDecorator

Example

ts
@Security('bearerAuth', ['users:write'])
@Security('apiKey')            // OR: either satisfies the route
deleteUser() {}