Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks should support a callback for conditionally running #210

Closed
ekryski opened this Issue May 18, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@ekryski
Copy link
Member

ekryski commented May 18, 2016

Much like our other built-in hooks you should be able to pass a callback to determine whether the hook should be run.

Usage would be very similar. See docs.

@ekryski

This comment has been minimized.

Copy link
Member Author

ekryski commented Jun 30, 2016

We are going to be deprecating the callback functionality in the other hooks as we have come up with a better, more flexible solution. You can simply wrap any existing hooks in your own, like so:

import { hooks } from 'feathers-authentication';

exports.hashPassword = function(options) {
  // Add any custom options

  function(hook) {
    return new Promise((resolve, reject) => {
      if (myCondition !== true) {
        return resolve(hook);
      }

      // call the original hook
      hooks.hashPassword(options)(hook)
        .then(hook => {
          // do something custom
          resolve(hook);
        })
        .catch(error => {
          // do any custom error handling
          error.message = 'my custom message';
          reject(error);
        });
    });
  });
}

@ekryski ekryski closed this Jun 30, 2016

@ekryski ekryski removed the Backlog label Jun 30, 2016

@DominikTrenz

This comment has been minimized.

Copy link

DominikTrenz commented Dec 18, 2017

I think there is a error in the example.
function(hook) {
should be
return function(hook) {
or?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.