1

My code is below and the auth complete never gets triggered. I'm not sure why since this is direct from the epilogue docs.

dataplan.list.auth((req, res, context) => {
  console.log('authenticating')
  // return new Promise(function(resolve, reject) {
    console.log('auth with passport')
    passport.authenticate('jwt',{session: false}, function(err, user, info) {
      console.log('auth complete')
      if(err) {
        res.status(500);
        resolve(context.stop());
      }

      if(user) {
        resolve(context.continue());
      } else {
        context.error(new ForbiddenError());
      }
    });
  // }); 
})
Shamoon
  • 41,293
  • 91
  • 306
  • 570
  • FWIW, I used Epilogue on a project recently and regretted it. I found it buggy and the repo is no longer maintained (https://github.com/dchester/epilogue/issues/225) If you are at the beginning of your project, I suggest reconsidering using this library. – mcranston18 Mar 06 '18 at 17:09
  • 1
    Switched to `finale-rest`, which seems to be more maintained – Shamoon Mar 07 '18 at 15:39

1 Answers1

1

Ensure you are returning a promise in your middleware function. It appears you were doing this but had it crossed out.

dataplan.list.auth((req, res, context) => {
  return new Promise(resolve => {
    passport.authenticate('jwt', (err, user, expiry) => {
      if(err) {
        res.status(500);
        return resolve(context.stop());
      }

      if(user) {
        resolve(context.continue());
      } else {
        return resolve(context.error(new ForbiddenError()));
      }
    })(req, res);
  });
});
mcranston18
  • 4,680
  • 3
  • 36
  • 37