From 4e8f3597fa0752ca35e1ea1a30661f5c1008e4fd Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Wed, 14 Mar 2018 15:20:06 +0200 Subject: [PATCH] Use basic auth only if there're env variables set --- server/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/index.js b/server/index.js index b75d3577..44c9da50 100644 --- a/server/index.js +++ b/server/index.js @@ -118,7 +118,13 @@ app.use(cookieParser()); if (!dev) { const USERNAME = process.env.BASIC_AUTH_USERNAME; const PASSWORD = process.env.BASIC_AUTH_PASSWORD; - app.use(auth.basicAuth(USERNAME, PASSWORD)); + const hasUsername = typeof USERNAME === 'string' && USERNAME.length > 0; + const hasPassword = typeof PASSWORD === 'string' && PASSWORD.length > 0; + + // If BASIC_AUTH_USERNAME and BASIC_AUTH_PASSWORD have been set - let's use them + if (hasUsername && hasPassword) { + app.use(auth.basicAuth(USERNAME, PASSWORD)); + } } const noCacheHeaders = {