1.0.1 • Published 7 years ago

feathers-authentication-disable-registration v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

Disable Registration

Easily prevent new User Creation in the Feathers Local User Service.

This is a Hook for the before create User Service Method. It's deadsimple to use and completely configurable, take a look at the example

Example without Options

...
import checkIfRegistrationIsDisabled from 'feathers-authentication-disable-registration'
...
userServiceHooks.before = {
  ...
  create: [
    checkIfRegistrationIsDisabled(),
    ...
  ],
  ...
};

To disable Registration simply set the following in your Feathers Server Configuration

{
  "host": "<>",
  "port": "<>",
  "public": "../public/",
  "auth": {
    "disableRegistration": true, // this disables registration
    "secret": "<>",
    "local": {}
  }
}

Options

You can pass an Options object with the following Parameters. By doing so you can basically disable any Service Method dynamically through the Feathers Configuration File.

{
  configPath: 'auth', // which key in the feathers config to use
  objectKey: 'disableRegistration', // which object key of the feathers configpath tu use
  errorMessage: 'Registration is currrently disabled' // message to throw in error
}

Usage Example with custom Options

Here you can see an example Configuration with the associated feathers configuration. Code for User Hooks:

...
import checkIfDisabled from 'feathers-authentication-disable-registration'
...
myCustomServiceHooks.before = {
  ...
  create: [
    checkIfDisabled({
      configPath: 'myCustomServiceConfig',
      objectKey: 'myCustomServiceConfigKey',
      errorMessage: 'myCustomCreateMessage'
    }),
    ...
  ],
  update: [
    checkIfDisabled({
      configPath: 'myCustomServiceConfig',
      objectKey: 'myCustomServiceConfigKeyUpdate',
      errorMessage: 'myCustomUpdateMessage'
    }),
    ...
  ],
  ...
};

Code for Feathers Configuration:

{
  "host": "<>",
  "port": "<>",
  "public": "../public/",
  "myCustomServiceConfig": {
  	"myCustomServiceConfigKey": true // this disables create method of customService,
    "myCustomServiceConfigKeyUpdate": false // update method should not be disabled
  },
  "auth": {
    "secret": "<>",
    "local": {}
  }
}