From ba004ae6563b284bfa978e71184d8c0bed81a487 Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 2 Sep 2020 23:07:44 -0700 Subject: [PATCH] oops, fix build errors from using future syntax worked in some local contexts, but the prod build failed! --- src/server/index.js | 9 +++++---- src/server/query-tests/User.test.js | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/server/index.js b/src/server/index.js index c0f7253..469e23b 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -1313,12 +1313,12 @@ async function getUserIdFromToken(token) { return null; } - const userId = payload.sub.match(/auth0\|impress-([0-9]+)/)?.[1]; - if (!userId) { + const subMatch = payload.sub.match(/auth0\|impress-([0-9]+)/); + if (!subMatch) { console.log("Unexpected auth token sub format", payload.sub); return null; } - + const userId = subMatch[1]; return userId; } @@ -1335,7 +1335,8 @@ const config = { }; lastSvgLogger = svgLogger; - const token = req.headers.authorization?.match(/^Bearer (.+)$/)?.[1]; + const tokenMatch = (req.headers.authorization || "").match(/^Bearer (.+)$/); + const token = tokenMatch && tokenMatch[1]; const currentUserId = await getUserIdFromToken(token); return { diff --git a/src/server/query-tests/User.test.js b/src/server/query-tests/User.test.js index 71753e0..2031bd0 100644 --- a/src/server/query-tests/User.test.js +++ b/src/server/query-tests/User.test.js @@ -3,6 +3,9 @@ const { query, getDbCalls, logInAsTestUser } = require("./setup.js"); describe("User", () => { it("looks up a user", async () => { + // TODO: I'm not sure why this is taking extra time, maybe the db conn? + jest.setTimeout(10000); + const res = await query({ query: gql` query {