Repository: freeCodeCamp/freeCodeCamp
File: api/src/routes/protected/challenge.ts (TypeScript)

Code before:
          fastify.errorHandler(error, req, reply);
        }
      }
    },
    async (req, reply) => {
      const logger = fastify.log.child({ req });
      logger.info(`User ${req.user?.id} submitted a coderoad challenge`);

      const { 'coderoad-user-token': encodedUserToken } = req.headers;
      const { tutorialId } = req.body;

      let userToken;
      try {
        const payload = jwt.verify(encodedUserToken, JWT_SECRET) as JwtPayload;
        userToken = payload.userToken;
      } catch {
        logger.warn('Invalid user token');
        void reply.code(400);
        return { type: 'error', msg: `invalid user token` } as const;
      }

      const tutorialRepo = tutorialId.split(':')[0];
      const tutorialOrg = tutorialRepo?.split('/')?.[0];

      if (tutorialOrg !== 'freeCodeCamp') {
        logger.warn('Tutorial not hosted on freeCodeCamp GitHub account');
        void reply.code(400);
        return {
          type: 'error',
          msg: `Tutorial not hosted on freeCodeCamp GitHub account`
        } as const;
      }

      const codeRoadChallenges = challenges.filter(
        ({ challengeType }) =>
          challengeType === challengeTypes.codeAllyPractice ||
          challengeType === challengeTypes.codeAllyCert
      );

      const challenge = codeRoadChallenges.find(challenge => {
        return tutorialRepo && challenge.url?.endsWith(tutorialRepo);
      });

      if (!challenge) {
        logger.warn(`Tutorial repo, ${tutorialRepo}, is not valid`);
        void reply.code(400);
        return { type: 'error', msg: 'Tutorial name is not valid' } as const;
      }

      const { id: challengeId, challengeType } = challenge;
      try {

Review comment (suggestion):
```suggestion
        logger.warn({ tutorialId }, 'Tutorial not hosted on freeCodeCamp GitHub account');
```

Code after:
          fastify.errorHandler(error, req, reply);
        }
      }
    },
    async (req, reply) => {
      const logger = fastify.log.child({ req });
      logger.info(
        { userId: req.user?.id },
        'User submitted a coderoad challenge'
      );

      const { 'coderoad-user-token': encodedUserToken } = req.headers;
      const { tutorialId } = req.body;

      let userToken;
      try {
        const payload = jwt.verify(encodedUserToken, JWT_SECRET) as JwtPayload;
        userToken = payload.userToken;
      } catch {
        logger.warn('Invalid user token');
        void reply.code(400);
        return { type: 'error', msg: `invalid user token` } as const;
      }

      const tutorialRepo = tutorialId.split(':')[0];
      const tutorialOrg = tutorialRepo?.split('/')?.[0];

      if (tutorialOrg !== 'freeCodeCamp') {
        logger.warn(
          { tutorialId },
          'Tutorial not hosted on freeCodeCamp GitHub account'
        );
        void reply.code(400);
        return {
          type: 'error',
          msg: `Tutorial not hosted on freeCodeCamp GitHub account`
        } as const;
      }

      const codeRoadChallenges = challenges.filter(
        ({ challengeType }) =>
          challengeType === challengeTypes.codeAllyPractice ||
          challengeType === challengeTypes.codeAllyCert
      );

      const challenge = codeRoadChallenges.find(challenge => {
        return tutorialRepo && challenge.url?.endsWith(tutorialRepo);
      });

      if (!challenge) {
        logger.warn({ tutorialRepo }, 'Tutorial repo is not valid');