From 567cbfc044a8c61cb60e693ee52b6b08232c6c97 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Wed, 30 Aug 2023 00:50:30 +0200 Subject: [PATCH] fix: use env.ts to get JWT_SECRET (#51424) --- api/src/routes/challenge.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/api/src/routes/challenge.ts b/api/src/routes/challenge.ts index a5f7e02b3bf..362f67c66f8 100644 --- a/api/src/routes/challenge.ts +++ b/api/src/routes/challenge.ts @@ -1,12 +1,12 @@ import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'; import jwt from 'jsonwebtoken'; import { uniqBy } from 'lodash'; -import { jwtSecret } from '../../../api-server/config/secrets'; import { getChallenges } from '../utils/get-challenges'; import { updateUserChallengeData } from '../utils/common-challenge-functions'; import { formatValidationError } from '../utils/error-formatting'; import { schemas } from '../schemas'; import { getPoints, ProgressTimestamp } from '../utils/progress'; +import { JWT_SECRET } from '../utils/env'; import { challengeTypes } from '../../../config/challenge-types'; import { canSubmitCodeRoadCertProject, @@ -65,8 +65,11 @@ export const challengeRoutes: FastifyPluginCallbackTypebox = ( } try { - if (typeof encodedUserToken === 'string' && jwtSecret) { - const payload = jwt.verify(encodedUserToken, jwtSecret) as JwtPayload; + if (typeof encodedUserToken === 'string') { + const payload = jwt.verify( + encodedUserToken, + JWT_SECRET + ) as JwtPayload; userToken = payload.userToken; } } catch {