Event Hooks

Depending on the nature of your app, in some instances, it may be helpful to know when certain account actions are taken (e.g., for the purposes of auditing and administration). To help in this process, Joystick offers account event hooks that can be defined via the accounts.events option passed via the options object passed to joystick.app(). Account hooks are called immediately after the corresponding account event takes place.

/index.server.js

import joystick from '@joystick.js/node';

joystick.app({
  accounts: {
    events: {
      on_login: ({ token, token_expires_at, user }) => {
        // Handle login event...
      },
      on_signup: ({ token, token_expires_at, user }) => {
        // Handle signup event...
      },
      on_logout: (user = {}) => {
        // Handle logout event...
      },
      on_recover_password: (email_address = '') => {
        // Handle recover password event...
      },
      on_reset_password: ({ token, token_expires_at, user }) => {
        // Handle reset password event...
      },
    },
  },
  routes: { ... }
});