aladov3.13.0

Docs/Controllers

@accessControl

Attaches an access control pipeline to a route.

TypeScript
@patch('/user/:id', { tags: ['User'] })
@accessControl([
  {
    inputProperty: 'auth.user.id',
    transformInputProperty: async (v: unknown) => v.toString(),
    compareWithProperty: 'path.id',
    statusCode: 403,
    message: 'Access Denied',
  },
])
@withAuth(bearerAuth)
@defineRequest({ path: Id, body: UserDto })
async update(req: Request) {
  console.log(req.auth.user); // injected by the auth handler
}

If either compared value is missing, access is denied.

Several rules can be given the same way as auth strategies (3.9.11): @accessControl([isMember, isOwner]) needs both, @accessControl(isAdmin, isEditor) either. See Access Control for full config details and how several rules combine.