Skip to content

Latest commit

 

History

History
79 lines (59 loc) · 2.26 KB

HOOKS.md

File metadata and controls

79 lines (59 loc) · 2.26 KB

Auth Hooks Spec'ing

See:

Currently:

keystone.createAuthStrategy({
  type: PasswordAuthStrategy,
  list: 'User',
  hooks: {
    resolveAuthInput: async (...) => {...},
    validateAuthInput: async (...) => {...},
    beforeAuth: async (...) => {...},
    afterAuth: async (...) => {...},

    beforeUnauth: async (...) => {...},
    afterUnauth: async (...) => {...},
  },
});

New Operations

We now have more potential auth-related operations:

  • authenticate (existing)
  • unauthenticate (existing)
  • createInitialItem
  • sendPasswordResetLink
  • redeemPasswordResetLink
  • sendMagicAuthLink
  • redeemMagicAuthLink

(See existing operations.)

Opinions

  • We don't need hooks for the createInitialItem operation, it's once off
    • Or.. is this how we collect metrics from the demo projects?
  • We should maintain the separation between "resolve" (can modify resolvedData) AND "validate" (can add validation errors) for auth hooks
  • We should reuse the existing resolveAuthInput and validateAuthInput functions for the new auth operations (as we do with update/create)

Usage

So usage becomes something like...?

keystone.createAuthStrategy({
  type: PasswordAuthStrategy,
  list: 'User',
  hooks: {
    resolveAuthInput: async (...) => {...},
    validateAuthInput: async (...) => {...},

    beforeAuth: async (...) => {...},
    afterAuth: async (...) => {...},

    beforeUnauth: async (...) => {...},
    afterUnauth: async (...) => {...},

    beforeSendPasswordResetLink: async (...) => {...},
    afterSendPasswordResetLink: async (...) => {...},

    beforeRedeemPasswordResetLink: async (...) => {...},
    afterRedeemPasswordResetLink: async (...) => {...},

    beforeSendMagicAuthLink: async (...) => {...},
    afterSendMagicAuthLink: async (...) => {...},

    beforeRedeemMagicAuthLink: async (...) => {...},
    afterRedeemMagicAuthLink: async (...) => {...},
  },
});