Setu-TS
    Preparing search index...

    Function RequirePolicy

    • Requires a policy ability on a route.

      Refused at register() when no authorization policy service is registered (register AuthPlugin), or when the policy or ability is not registered. Per request: 401 when the ability denies an anonymous request, 403 when it denies a signed-in principal, otherwise the route continues. Repeatable: every @RequirePolicy on a route must allow, evaluated top to bottom. Runs after guards and @Roles/@Permissions, and before interceptors, middleware and validation — so a target extractor reading the body sees the UNVALIDATED body; prefer route parameters.

      Type Parameters

      Parameters

      • policy: C

        A @Policy class

      • ability: K

        One of its ability methods

      • Optionaltarget: PolicyTarget<PolicyClassTarget<C, K>>

        A fixed target, or an extractor called per request

      Returns SetuMethodDecorator

      A standard method decorator

      @Patch('/:id')
      @RequirePolicy(PostPolicy, 'update', (ctx) => posts.find(ctx.params.id))
      update() { … }

      0.9.0

    • Requires an ability of a definePolicy definition on a route.

      Type Parameters

      • A extends string
      • T

      Parameters

      • policy: PolicyDefinition<A, T>

        A policy definition

      • ability: A

        One of its ability names

      • Optionaltarget: PolicyTarget<T>

        A fixed target, or an extractor called per request

      Returns SetuMethodDecorator

      A standard method decorator

      0.9.0