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 {