LM1LC3N7 / nodebb-plugin-private-forum

A NodeBB plugin to lockdown the forum to non-registered users.
MIT License
3 stars 1 forks source link

This plug-in appears to generate errors for anonymous visits #2

Closed wu-lee closed 3 years ago

wu-lee commented 3 years ago

After installing this plug-in (v1.0.0 on NodeBB v1.16.0, Lavender theme v5.0.17) , I've noticed new errors appearing both in the browser console, and the server logs.

To reproduce this, I visit the site as an anonymous user, and click on a public category title which is visible. This does nothing visible, but in the console logs are the following errors. These errors disappear when I disable this plug-in and rebuild, and re-appear again when it is enabled (and rebuilt). I don't seem to see these errors when visiting as a logged-in user.

Uncaught TypeError: t.template is undefined
    go ajaxify.js:70
    success ajaxify.js:387
    jQuery 6
    loadData ajaxify.js:361
    go ajaxify.js:59
    c ajaxify.js:461
    e ajaxify.js:524
    jQuery 8
    load app.js:78
    <anonymous> app.js:23
    jQuery 12
ajaxify.js:70:3

And these server-side:

Jan 20 22:51:22 2021-01-20T22:51:22.757Z [4567/480] - error: /service-worker.js
Jan 20 22:51:22 Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Jan 20 22:51:22 at ServerResponse.setHeader (_http_outgoing.js:485:11)
Jan 20 22:51:22 at ServerResponse.header (/run/nodebb/node_modules/express/lib/response.js:771:10)
Jan 20 22:51:22 at ServerResponse.contentType (/run/nodebb/node_modules/express/lib/response.js:599:15)
Jan 20 22:51:22 at /app/code/src/routes/meta.js:15:19
Jan 20 22:51:22 at Layer.handle [as handle_request] (/run/nodebb/node_modules/express/lib/router/layer.js:95:5)
Jan 20 22:51:22 at next (/run/nodebb/node_modules/express/lib/router/route.js:137:13)
Jan 20 22:51:22 at Route.dispatch (/run/nodebb/node_modules/express/lib/router/route.js:112:3)
Jan 20 22:51:22 at Layer.handle [as handle_request] (/run/nodebb/node_modules/express/lib/router/layer.js:95:5)
Jan 20 22:51:22 at /run/nodebb/node_modules/express/lib/router/index.js:281:22
Jan 20 22:51:22 at Function.process_params (/run/nodebb/node_modules/express/lib/router/index.js:335:12)
Jan 20 22:51:22 (node:480) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Jan 20 22:51:22 at ServerResponse.setHeader (_http_outgoing.js:485:11)
Jan 20 22:51:22 at ServerResponse.header (/run/nodebb/node_modules/express/lib/response.js:771:10)
Jan 20 22:51:22 at ServerResponse.send (/run/nodebb/node_modules/express/lib/response.js:170:12)
Jan 20 22:51:22 at ServerResponse.renderOverride [as render] (/app/code/src/middleware/render.js:78:10)
Jan 20 22:51:22 at processTicksAndRejections (internal/process/task_queues.js:93:5)
Jan 20 22:51:22 (node:480) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
Jan 20 22:51:22 (node:480) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
LM1LC3N7 commented 3 years ago

Hello,

I suspect that a file is blocked by the module when not logged in. Do you have the same error when you log in?

I should allow file access based on a regex to allow all js and css files. When I have a little time I will try to update this.

wu-lee commented 3 years ago

No, the error doesn't seem to show up when I'm logged in.

LM1LC3N7 commented 3 years ago

This is the normal behaviour: when not logged in, URL access are restricted. When logged in, nothing is restricted anymore.

LM1LC3N7 commented 3 years ago

I have created a new release, it should automatically update the npm repo.

I no longer have a nodebb forum, can you test this new version and check:

LM1LC3N7 commented 3 years ago

1.0.1b is alive. https://www.npmjs.com/package/nodebb-plugin-private-forum

wu-lee commented 3 years ago

Thanks - currently running our forum without this package, but haven't had time to test it so far, sorry.

LM1LC3N7 commented 3 years ago

I just tried my plugin on a fresh NodeBB installation.

It appears that the behaviour you described is completely normal when you are not logged in. The Lavender theme seems not to handle the error when you are trying to access to a page that is protected by my module.

I am searching for a way to force the Lavender theme (or the nodeBB interface) to redirect to the login page.

LM1LC3N7 commented 3 years ago

Solved! https://github.com/LM1LC3N7/nodebb-plugin-private-forum/releases/tag/1.0.2b https://www.npmjs.com/package/nodebb-plugin-private-forum