Redirect to login
-
Hello @baris and @magnusvhendin
I would like to update my module nodebb-plugin-private-forum that should do exactly what you are trying to archive.
But it seems it is not working well with v1.16.2 and I need some help on the Hook declaration.I understand that I need to use
response:router.page
, but how exactly?
Is this ok for you?plugin.json
{ "id": "nodebb-plugin-private-forum", "url": "https://github.com/LM1LC3N7/nodebb-plugin-private-forum", "library": "./library.js", "hooks": [{ "hook": "response:router.page", "method": "init" }] }
library.json
'use strict'; const plugin = {}; var winston = module.parent.require('winston'); const helpers = require.main.require('./src/controllers/helpers'); plugin.init = async (data) => { const allowedPages = /\/(assets\/|login|register|reset|plugins\/).*|.*(.css|.js)$/; winston.verbose("[plugin-nodebb-private-forum] Checking URL ("+ req.url +"), redirection."); # Allow only few pages or logged in users if (data.req.loggedIn || allowedPages.test(req.url)) { return data; } # else redirect to /login. winston.verbose("[plugin-nodebb-private-forum] User is NOT logged or URL is NOT allowed."); return Helpers.notAllowed(data.req, data.res); }; module.exports = plugin;
I can't see any of the debug log messages containing accessed URL
-
@baris I'm also trying this and it works with SSO also. However now I can't logout and use /login?local=1 to log the admin account as above method force only use /login and it use the sso. Any clue, hint to avoid this?
I use the code in here
https://github.com/LM1LC3N7/nodebb-plugin-private-forum/blob/master/library.js -
Hello @jalathpc_demo
I tried to create a patch:
https://github.com/LM1LC3N7/nodebb-plugin-private-forum/releases/tag/v1.3.1I no longer have a NodeBB instance, so let me know if it works (I am honestly not sure, as
/logout
should be allowed as you are logged in.It would be interesting to check if
req.loggedIn
is correctly set when using SSO. This could be why the plugin is not working as you need.NPM link: https://www.npmjs.com/package/nodebb-plugin-private-forum/v/1.3.1