MCPcopy Index your code
hub / github.com/freeCodeCamp/freeCodeCamp / settingRedirectRoutes

Function settingRedirectRoutes

api/src/routes/protected/settings.ts:812–924  ·  view source on GitHub ↗
(
  fastify,
  _options,
  done
)

Source from the content-addressed store, hash-verified

810 * @param done Callback to signal that the logic has completed.
811 */
812export const settingRedirectRoutes: FastifyPluginCallbackTypebox = (
813 fastify,
814 _options,
815 done
816) => {
817 const redirectMessage = {
818 type: 'danger',
819 content:
820 'Oops! Something went wrong. Please try again in a moment or contact support@freecodecamp.org if the error persists.'
821 } as const;
822
823 const expirationMessage = {
824 type: 'info',
825 content:
826 'The link to confirm your new email address has expired. Please try again.'
827 } as const;
828
829 const successMessage = {
830 type: 'success',
831 content: 'flash.email-valid'
832 } as const;
833
834 async function updateEmail(
835 fastify: FastifyInstance,
836 { id, email }: { id: string; email: string }
837 ) {
838 await fastify.prisma.user.update({
839 where: { id },
840 data: {
841 email,
842 emailAuthLinkTTL: null,
843 emailVerified: true,
844 emailVerifyTTL: null,
845 newEmail: null
846 }
847 });
848 }
849
850 async function deleteAuthToken(
851 fastify: FastifyInstance,
852 { id }: { id: string }
853 ) {
854 await fastify.prisma.authToken.delete({
855 where: { id }
856 });
857 }
858
859 fastify.get(
860 '/confirm-email',
861 {
862 schema: schemas.confirmEmail,
863 errorHandler(error, request, reply) {
864 const logger = fastify.log.child({ req: request });
865 if (error.validation) {
866 logger.warn({ validationError: error.validation });
867 const { origin } = getRedirectParams(request);
868 void reply.redirectWithMessage(origin, redirectMessage);
869 } else {

Callers

nothing calls this directly

Calls 5

getRedirectParamsFunction · 0.85
isExpiredFunction · 0.85
updateEmailFunction · 0.85
deleteAuthTokenFunction · 0.85
doneFunction · 0.85

Tested by

no test coverage detected