Skip to content

Adding plugins

François Billioud edited this page May 5, 2019 · 6 revisions

Adding plugins

You can add plugins that we provide, or create your own if you like.

Provided plugins

Login

Right now, the only plugin that we are providing is a plugin to handle login to the server through a JWT token or a couple email/password. Of course, this is just a beginning.

The login plugin takes an object parameter containing 4 properties:

  • userTable : The name of the table beeing used to store the users
  • login : The column being used to store the logins
  • password : The column being used to store the passwords
  • salt (optional) : The column being used to store the salts encrypting the password

Example

const { login : { loginPlugin } } = require('simpleql');
const plugins = [
  loginPlugin({
    login: 'email',
    password: 'password',
    salt: 'salt',
    userTable: 'User',
  }),
];

To log into a table, just send the following request:

const request = {
  User : {
    email : 'myLogin',
    password : 'myPassword',
  }
}

You will receive a SimpleQL response of this type

{
  User : {
    email : 'myLogin',
    jwt : 'jwt token',
  }
}

Create your own plugin

['middleware', 'onRequest', 'onCreation', 'onDeletion', 'onResult', 'preRequisite', 'errorHandler']; A plugin consist in an object containing the following optional properties:

  • preRequisite : A function that will make sure that the plugin is correctly configured.
  • middleware : A middleware that might intercept the whole request.
  • onRequest : An object containing functions being call before any request in a specific table.
  • onCreation : An object containing functions being call each time an element is created into a specific table.
  • onDeletion : An object containing functions being call each time an element is deleted from a specific table.
  • onResult : An object containing functions being call after a request was resolved in a specific table.
  • errorHandler : A middleware able to handle errors generated by this plugin.

Prerequisite

middleware

onRequest

onCreation

onDeletion

onResult

errorHandler

Clone this wiki locally