From 5bf037b19381eecf918297e992b59af7b48bc4a0 Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 17 Aug 2022 16:15:09 -0700 Subject: [PATCH] Oops, fix bug on boot caused by login changes I forgot that we sometimes use the Apollo server in a context where `req` and `res` aren't present! (namely in our `build-cached-data` script.) In this change, we update the DTI-Auth-Mode HTTP header check to be cognizant that the request might be absent! --- src/server/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/index.js b/src/server/index.js index 5b98037..239480f 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -67,10 +67,10 @@ const config = { context: async ({ req, res }) => { const db = await connectToDb(); - let authMode = req.headers["dti-auth-mode"] || "auth0"; + let authMode = req?.headers?.["dti-auth-mode"] || "auth0"; let currentUserId; if (authMode === "auth0") { - const auth = (req && req.headers && req.headers.authorization) || ""; + const auth = req?.headers?.authorization || ""; const authMatch = auth.match(/^Bearer (.+)$/); const token = authMatch && authMatch[1]; currentUserId = await getUserIdFromTokenViaAuth0(token);