Use response:router.page instead of filter:router.page (deprecated)

Technical Support
  • Hello !

    I'm upgrading my plugins and I have a problem. I get this message in my nodebb 1.15.5 logs :

    2021-01-01T17:32:47.395Z [5678/284882] - warn: [plugins/nodebb-plugin-forcelogin-YA] Hook "filter:router.page" is deprecated, please use "response:router.page" instead.
    

    so I want to change the hook I use in my plugin. I changed in plugin.json filter to response but it gives error on running after this change. How must I change the following function called by this hook ?

    plugin.YAfonction = function(req, res, next) {
    	if (!req.uid && !req.originalUrl.startsWith(nconf.get('relative_path') + '/login') && !req.originalUrl.startsWith(nconf.get('relative_path') + '/api/login') && !req.originalUrl.startsWith(nconf.get('relative_path') + '/api/reset') && !req.originalUrl.startsWith(nconf.get('relative_path') + '/reset')) {
    		helpers.notAllowed(req,res);
    	} else {
    		next();
    	}
    };
    

    May be it's simple... But I'm not a great programmer...
    Thanks in advance !

  • @alfazaz looks like you need to change your function from something like

    function hook(req, res, next) { ... }
    

    To something like

    function hook(data, next) {
        var req = data.req; var res = data.res;
        ...
    }
    
  • @pitaj Thanks ! It worked (without next in fact).

  • @alfazaz That's the thing about response hooks, they're awaited, and next is not checked. NodebB will check if you have sent a response to the end-user, and if you have, automatically wrap up the plugin hook call.

  • @julian Yes. I saw it. Thanks !


Suggested Topics