From e45aab639fb9006c8f78402226eb42b0948175fa Mon Sep 17 00:00:00 2001 From: emad-salah Date: Fri, 30 Oct 2020 15:28:10 +0100 Subject: [PATCH] HTTP Routes now have an isAuthenticated middleware that returns a 401 error if the user is unauthenticated --- src/routes.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/routes.js b/src/routes.js index 5e184349..bef2da4e 100644 --- a/src/routes.js +++ b/src/routes.js @@ -416,6 +416,17 @@ module.exports = async ( errorMessage: 'Please create a wallet before using the API' }) } + + if (req.path.includes('/api/gun')) { + const authenticated = GunDB.isAuthenticated() + + if (!authenticated) { + return res.status(401).json({ + field: 'gun', + errorMessage: 'Please login in order to perform this action' + }) + } + } next() } catch (err) { logger.error(err)