Stone.js API
    Preparing search index...
    • Method decorator: state what a handler requires of its caller.

      @Protect()                    // authenticated
      @Protect('tasks:write') // authenticated, holding that scope
      @Protect(['a', 'b']) // authenticated, holding both

      Like @Validate and @Returns, this knows nothing about the router: the requirement is recorded on the handler under this module's own key, so it holds in a routed application, a single-handler service, a CLI command or the browser. When a router is in play you may put it on the route instead (@Get('/me', { auth: true })), which keeps everything a route does in one place.

      Stating it on the handler rather than wiring a guard by hand is what lets @stone-js/openapi publish the endpoint as protected: a requirement that only exists inside a middleware list cannot be read by anything else.

      Type Parameters

      • T extends Function = Function

      Parameters

      • auth: ProtectInput = true

        What the handler requires. Defaults to authentication alone.

      Returns MethodDecorator

      A method decorator.