julianlam / nodebb-plugin-session-sharing

Allows login sessions from your app to persist in NodeBB
MIT License
88 stars 65 forks source link

Add Hooks to normalize payload and error validation #54

Closed uplift closed 5 years ago

uplift commented 6 years ago

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?

https://github.com/julianlam/nodebb-plugin-session-sharing/blob/1a554696f40f130f5a824ed0d9bf1cb207875d60/library.js#L191

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)?

https://github.com/julianlam/nodebb-plugin-session-sharing/blob/1a554696f40f130f5a824ed0d9bf1cb207875d60/library.js#L417 https://github.com/julianlam/nodebb-plugin-session-sharing/blob/1a554696f40f130f5a824ed0d9bf1cb207875d60/library.js#L421 https://github.com/julianlam/nodebb-plugin-session-sharing/blob/1a554696f40f130f5a824ed0d9bf1cb207875d60/library.js#L425 https://github.com/julianlam/nodebb-plugin-session-sharing/blob/1a554696f40f130f5a824ed0d9bf1cb207875d60/library.js#L429

Thanks

julianlam commented 6 years ago

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

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);
}
uplift commented 6 years ago

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.

uplift commented 5 years ago

Finally got round to looking at this. Have sent a pull request here - https://github.com/julianlam/nodebb-plugin-session-sharing/pull/59

julianlam commented 5 years ago

https://github.com/julianlam/nodebb-plugin-session-sharing/pull/59 & v4.3.1