fix: use env.ts to get JWT_SECRET (#51424)

This commit is contained in:
Oliver Eyton-Williams
2023-08-30 00:50:30 +02:00
committed by GitHub
parent cb9d6a6243
commit 567cbfc044

View File

@@ -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 {