MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / authorize

Function authorize

packages/authorization/src/decorators/authorize.ts:90–123  ·  view source on GitHub ↗
(spec: AuthorizationMetadata)

Source from the content-addressed store, hash-verified

88 * @param spec Authorization metadata
89 */
90export function authorize(spec: AuthorizationMetadata) {
91 return function authorizeDecoratorForClassOrMethod(
92 // Class or a prototype
93 // eslint-disable-next-line @typescript-eslint/no-explicit-any
94 target: any,
95 method?: string,
96 // Use `any` to for `TypedPropertyDescriptor`
97 // See https://github.com/loopbackio/loopback-next/pull/2704
98 // eslint-disable-next-line @typescript-eslint/no-explicit-any
99 methodDescriptor?: TypedPropertyDescriptor<any>,
100 ) {
101 if (method && methodDescriptor) {
102 // Method
103 return AuthorizeMethodDecoratorFactory.createDecorator(
104 AUTHORIZATION_METHOD_KEY,
105 spec,
106 {decoratorName: '@authorize'},
107 )(target, method, methodDescriptor!);
108 }
109 if (typeof target === 'function' && !method && !methodDescriptor) {
110 // Class
111 return AuthorizeClassDecoratorFactory.createDecorator(
112 AUTHORIZATION_CLASS_KEY,
113 spec,
114 {decoratorName: '@authorize'},
115 )(target);
116 }
117 // Not on a class or method
118 throw new Error(
119 '@intercept cannot be used on a property: ' +
120 DecoratorFactory.getTargetName(target, method, methodDescriptor),
121 );
122 };
123}
124
125export namespace authorize {
126 /**

Callers 13

OrderControllerClass · 0.90
ProjectControllerClass · 0.90
allowFunction · 0.85
denyFunction · 0.85
scopeFunction · 0.85
voteFunction · 0.85
allowAllExceptFunction · 0.85
denyAllExceptFunction · 0.85
skipFunction · 0.85
TestClassClass · 0.85
SubTestClassClass · 0.85
OrderControllerClass · 0.85

Calls 2

getTargetNameMethod · 0.80
createDecoratorMethod · 0.45

Tested by

no test coverage detected