Skip to content

Variable: OnBeforeHandle

ts
const OnBeforeHandle: (options?) => MethodDecorator;

Defined in: packages/core/src/decorators/lifecycle.decorators.ts:133

Hook called before request handler

Parameters

ParameterTypeDescription
options?{ before?: boolean; }-
options.before?booleanInsert before other hooks

Returns

MethodDecorator

See

https://elysiajs.com/essential/life-cycle.html#on-before-handle

Example

typescript
@Controller('/users')
export class UserController {
  @OnBeforeHandle()
  async checkAuth(context: Context) {
    if (!context.headers.authorization) {
      context.set.status = 401;
      return { error: 'Unauthorized' };
    }
  }
}

Released under the MIT License.