(spec: AuthorizationMetadata)
| 88 | * @param spec Authorization metadata |
| 89 | */ |
| 90 | export 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 | |
| 125 | export namespace authorize { |
| 126 | /** |
no test coverage detected