AuthorizationDecoratorsUtils
@quik/authorization / AuthorizationDecoratorsUtils
Variable: AuthorizationDecoratorsUtils
constAuthorizationDecoratorsUtils:object
Defined in: authorization/src/decorator.utils.ts:114
Type Declaration
EndpointMiddleware
EndpointMiddleware: (
security,endpointDecorator) => <This,Args,Return>(target,context) =>MethodDecoratorType<This,Args,Return>
Wraps an endpoint decorator with authorization metadata to secure API endpoints.
This function enhances existing endpoint decorators by adding security scheme information and marking the endpoint as requiring authentication. It registers the security scheme with the StrategiesStore to ensure it's included in API documentation.
Parameters
security
string | SecuritySchemeDecoratorOption
Name or configuration of the security scheme
endpointDecorator
MethodDecoratorType<any, any, any>
The underlying decorator to enhance
Returns
<This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>
Example
// Create a secured endpoint decorator
const SecuredEndpoint = AuthorizationDecoratorsUtils.EndpointMiddleware(
"bearer",
HttpDecorators.Get("/secure-data")
);
// Apply to a controller method
@SecuredEndpoint
async getSecureData() {
return { data: "This is protected" };
}
See
RouteMiddleware For applying authorization to an entire route class
RouteMiddleware
RouteMiddleware: <
Class>(security,routeDecorator) => (Value,context) =>Class
Applies authorization metadata to an entire route class, securing all endpoints within it.
This function enhances route class decorators by adding security scheme information and marking all endpoints in the route as requiring authentication. It registers the security scheme with the StrategiesStore to ensure it's included in API documentation.
Type Parameters
Class
Class extends Constructor<QRoute>
Parameters
security
string | SecuritySchemeDecoratorOption
Name or configuration of the security scheme
routeDecorator
(Value, context) => Class
Decorator applied on the route class
Returns
(Value, context) => Class
Example
// Create a secured route decorator
const SecuredRoute = AuthorizationDecoratorsUtils.RouteMiddleware(
"bearer",
HttpDecorators.Route("/admin")
);
// Apply to a controller class
@SecuredRoute
export class AdminController extends QRoute {
// All methods in this class will require authentication
@HttpDecorators.Get("/dashboard")
async getDashboard() {
return { stats: "Admin dashboard data" };
}
}
See
EndpointMiddleware For applying authorization to individual endpoints