From c238cb455b374d3ee78e6174a9470baefaa3c2ed Mon Sep 17 00:00:00 2001 From: "A. Koch" Date: Tue, 21 Aug 2018 16:20:09 +0200 Subject: [PATCH] only add author if user exists --- src/middleware/author.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/middleware/author.js b/src/middleware/author.js index 5ecc2f8..50f3f42 100644 --- a/src/middleware/author.js +++ b/src/middleware/author.js @@ -1,16 +1,18 @@ const setup = async function (api, profileService) { api.app.use(async (req, res, next) => { - const r = { - params: { - id: req.user.uuid - }, - user: req.user - } - req.user.profile = await profileService.getHandler(r) - if (req.method.toLowerCase() === 'post') { - req.body.author = { - id: req.user.uuid, - name: req.user.profile ? req.user.profile.name : undefined + if (req.user) { + const r = { + params: { + id: req.user.uuid + }, + user: req.user + } + req.user.profile = await profileService.getHandler(r) + if (req.method.toLowerCase() === 'post') { + req.body.author = { + id: req.user.uuid, + name: req.user.profile ? req.user.profile.name : undefined + } } } next() -- GitLab