( fastify, _options, done )
| 810 | * @param done Callback to signal that the logic has completed. |
| 811 | */ |
| 812 | export 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 { |
nothing calls this directly
no test coverage detected