Skip to content

Commit 9c8840d

Browse files
committed
fix: crash #425 req.body can be undefined
1 parent 6886a5e commit 9c8840d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

routes/v2/middleware.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ const passportAuthenticateAsync = function (req, res) {
3737

3838
Middleware.requireUser = async function (req, res, next) {
3939
var writeApi = require.main.require('nodebb-plugin-write-api');
40-
var token = (writeApi.settings['jwt:payloadKey'] ? (req.query[writeApi.settings['jwt:payloadKey']] || req.body[writeApi.settings['jwt:payloadKey']]) : null) || req.query.token || req.body.token;
40+
const query = req.query || {};
41+
const body = req.body || {};
42+
var token = (writeApi.settings['jwt:payloadKey'] ? (query[writeApi.settings['jwt:payloadKey']] || body[writeApi.settings['jwt:payloadKey']]) : null) || query.token || body.token;
4143
const loginAsync = util.promisify(req.login).bind(req);
4244
var routeMatch;
4345

0 commit comments

Comments
 (0)