Skip to content

Hook Context

ctx exposes runtime capability APIs to hook code.

Auth

  • ctx.auth.hasRole(role: string): boolean

Use this for role-aware business logic in hooks.

Example:

ts
if (ctx.auth.hasRole("admin")) {
  ctx.log.info("admin override path");
}

Database

  • ctx.db.findOne(...)
  • ctx.db.create(...)
  • ctx.db.update(...)
  • ctx.db.delete(...)

Use DB capabilities for controlled read/write side-effects inside hooks.

Logging

  • ctx.log.info(message: string, meta?: object)
  • ctx.log.warn(message: string, meta?: object)
  • ctx.log.error(message: string, meta?: object)

Use hook logs for runtime diagnostics and observability.

Notes

  • Use Access Policies for baseline request authorization.
  • Use hooks (and ctx) for business validation, enrichment, and side-effects.
  • Context shape is runtime-controlled; use only documented methods.