The plugin seamlessly handles account history events. When used with any auth plugin, an entry will be created in the history table, describing the action that occurred (login, logout, change password, etc). It does so by creating a new table (by default, account_history) and starts listening for auth:history events coming from the dispatcher.

For now, the plugin only works with store-sql, therefore it is a dependency you shoul have configured for your application.

Installation and usage
npm i --save thorin-plugin-auth-history@1.x
'use strict';
// app.js entry file
const thorin = require('thorin');

thorin.addPlugin(require('thorin-plugin-auth-history'));   // <- add this line => {});

# run to setup the models
node app.js --setup=plugin.auth-history
Default configuration
  • storesqlthe name of the SQL store your application uses
  • accountModelaccountthe code of your account model. We use this for foreign key definition setup in the history table.
  • history.modelNameaccountHistorythe name of the history model we're going to add.
  • history.tableNameaccount_historythe name of the history table that will be created.
  • eventsnullIf we want the history plugin to listen to specific events, set an array of events here.
History table fields
  • typestringthe event type: LOGIN, LOGOUT, etc.
  • user_agentstringthe user-agent of the account
  • ipstringthe IP address of the account
  • account_idintegera foreign key to the account table

If you want to add additional fields to the history table, create a new file in app/models/{opt.history.modelName}.js, and export a function called extend. It will receive the history model object and the Sequelize instance.

'use strict';
// File: app/models/accountHistory.js
module.exports = function extend(modelObj, Seq) {
      .field('location', Seq.STRING)
      .field('app_source', Seq.STRING)
      // add as many fields and methods you want.
Plugin functionality
pluginObj.create(accountObj, event, data) : Promise
Manually insert an account event in the history table.
Do you have a question or is something missing?

You can always create a new issue on GitHub or contact one of the core founders by chat.