julianlam/nodebb-plugin-session-sharing

Add Hooks to normalize payload and error validation

Closed this issue · 4 comments

Hi,

Would it be possible to fire a hook (passing in the payload and userData) in the normalizePayload function so we can do some custom normalizing of our app cookie data and custom validation on the payload?

winston.verbose('[session-sharing] Payload verified');

Also would it be possible to fire hooks after each error condition in the process callback for some custom error handling (passing in req, res, err, uid, plugin settings)?

winston.info('[session-sharing] uid ' + uid + ' is banned, not logging them in');

winston.warn('[session-sharing] The passed-in payload was invalid and could not be processed');

winston.info('[session-sharing] Payload valid, but local account not found. Assuming guest.');

winston.warn('[session-sharing] Error encountered while parsing token: ' + err.message);

Thanks

Look at you @uplift, getting all advanced with plugins firing hooks for other plugins to listen for 😄

I have no objection to this if you want to open a PR for filter:sessionSharing.normalizePayload, though for the errors, you can add this after if (err) {:

if (plugins.hasListeners('filter:sessionSharing.error')) {
  return plugins.fireHook('filter:sessionSharing.error', whatever, arguments, you, needed);
}

Haha, Trust me its better than the current approach I inherited :)

I'll try get something across in next couple of weeks as this is a background task for me currently.

Finally got round to looking at this. Have sent a pull request here - #59

#59 & v4.3.1