Skip to content

throwIfIsProvider

hooks
Source Code | Documentation

See also: predicates/isProvider

Throws a MethodNotAllowed error when the request comes from one of the specified transports. Combines throwIf with the isProvider predicate for a convenient one-liner. Use this to restrict methods to server-only or specific transport types.

ts
  import { 
throwIfIsProvider
} from 'feathers-utils/hooks';

Example

ts
import { throwIfIsProvider } from 'feathers-utils/hooks'

app.service('internal').hooks({
  before: { all: [throwIfIsProvider('external')] }
})

Type declaration

Show Type Declarations
ts
export type ThrowIfIsIsProviderOptions = {
  filter?: PredicateFn
  /**
   * Customize the error that is thrown if the context is a provider and the service does not allow it.
   * If not provided, throws a `MethodNotAllowed` error.
   */
  error?: (context: HookContext) => FeathersError
}
/**
 * Throws a `MethodNotAllowed` error when the request comes from one of the specified transports.
 * Combines `throwIf` with the `isProvider` predicate for a convenient one-liner.
 * Use this to restrict methods to server-only or specific transport types.
 *
 * @example
 * ```ts
 *
 *
 * app.service('internal').hooks({
 *   before: { all: [throwIfIsProvider('external')] }
 * })
 * ```
 *
 * @see https://utils.feathersjs.com/hooks/throw-if-is-provider.html
 */
export declare const throwIfIsProvider: <H extends HookContext = HookContext>(
  transports: TransportName | TransportName[],
  options?: ThrowIfIsIsProviderOptions,
) => (context: H, next?: HookContext) => Promise<any>
ArgumentTypeDescription
transportsTransportName | TransportName[]
optionsThrowIfIsIsProviderOptions
typemethodsmulti
before, after, aroundcreate, update, patchyes

Released under the MIT License.