Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
⚰️ Remove dead verification code (#566)
Luke Vella7470cfecdf78
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex 3d2c50f57..a650276d9 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -53,7 +53,6 @@"hide": "Hide","home": "Home","ifNeedBe": "If need be",- "linkHasExpired": "Your link has expired or is no longer valid","loading": "Loading…","loadingParticipants": "Loading participants…","location": "Location",@@ -104,7 +103,6 @@"participantCount_two": "{{count}} participants","participantCount_zero": "{{count}} participants","pollHasBeenLocked": "This poll has been locked",- "pollHasBeenVerified": "Your poll has been verified","pollOwnerNotice": "Hey {{name}}, looks like you are the owner of this poll.","pollsEmpty": "No polls created","possibleAnswers": "Possible answers",diff --git a/apps/web/src/components/admin-control.tsx b/apps/web/src/components/admin-control.tsxindex aaa8c3ce0..9ddf4fe11 100644--- a/apps/web/src/components/admin-control.tsx+++ b/apps/web/src/components/admin-control.tsx@@ -4,30 +4,23 @@ import { useTranslation } from "next-i18next";import posthog from "posthog-js";import React from "react";import toast from "react-hot-toast";-import { useMount } from "react-use";import { Button } from "@/components/button";import Share from "@/components/icons/share.svg";-import { trpc } from "../utils/trpc";import { useParticipants } from "./participants-provider";import ManagePoll from "./poll/manage-poll";import { useUpdatePollMutation } from "./poll/mutations";import NotificationsToggle from "./poll/notifications-toggle";import { usePoll } from "./poll-context";import Sharing from "./sharing";-import { useUser } from "./user-provider";export const AdminControls = (props: { children?: React.ReactNode }) => {- const { poll, urlId } = usePoll();+ const { urlId } = usePoll();const { t } = useTranslation("app");const router = useRouter();- const queryClient = trpc.useContext();-- const session = useUser();-const { mutate: updatePollMutation } = useUpdatePollMutation();React.useEffect(() => {@@ -47,37 +40,12 @@ export const AdminControls = (props: { children?: React.ReactNode }) => {}}, [urlId, router, updatePollMutation, t]);- // TODO (Luke Vella) [2023-03-10]: We can delete this after 2.3.0 is released- const verifyEmail = trpc.polls.verification.verify.useMutation({- onSuccess: () => {- toast.success(t("pollHasBeenVerified"));- queryClient.polls.invalidate();- session.refresh();- posthog.capture("verified email");- },- onError: () => {- toast.error(t("linkHasExpired"));- },- onSettled: () => {- router.replace(`/admin/${router.query.urlId}`, undefined, {- shallow: true,- });- },- });-const { participants } = useParticipants();const [isSharingVisible, setIsSharingVisible] = React.useState(participants.length === 0,);- useMount(() => {- const { code } = router.query;- if (typeof code === "string" && !poll.verified) {- verifyEmail.mutate({ code, pollId: poll.id });- }- });-return (<div className=""><div className="mb-3 flex justify-end sm:mb-4">diff --git a/apps/web/src/server/routers/polls.ts b/apps/web/src/server/routers/polls.tsindex b6c0f4c08..e18799cbc 100644--- a/apps/web/src/server/routers/polls.ts+++ b/apps/web/src/server/routers/polls.ts@@ -12,7 +12,6 @@ import { possiblyPublicProcedure, publicProcedure, router } from "../trpc";import { comments } from "./polls/comments";import { demo } from "./polls/demo";import { participants } from "./polls/participants";-import { verification } from "./polls/verification";const defaultSelectFields: {id: true;@@ -251,7 +250,6 @@ export const polls = router({demo,participants,comments,- verification,// END LEGACY ROUTESenableNotifications: possiblyPublicProcedure.input(z.object({ adminUrlId: z.string() }))diff --git a/apps/web/src/server/routers/polls/verification.ts b/apps/web/src/server/routers/polls/verification.tsdeleted file mode 100644index a4d3351e4..000000000--- a/apps/web/src/server/routers/polls/verification.ts+++ /dev/null@@ -1,60 +0,0 @@-import { prisma } from "@rallly/database";-import { TRPCError } from "@trpc/server";-import { z } from "zod";--import { decryptToken, mergeGuestsIntoUser } from "../../../utils/auth";-import { publicProcedure, router } from "../../trpc";--export const verification = router({- verify: publicProcedure- .input(- z.object({- pollId: z.string(),- code: z.string(),- }),- )- .mutation(async ({ ctx, input }) => {- const payload = await decryptToken<{- pollId: string;- }>(input.code);-- if (!payload) {- throw new TRPCError({- code: "BAD_REQUEST",- message: "Invalid token",- });- }-- const { pollId } = payload;-- if (pollId !== input.pollId) {- throw new TRPCError({- code: "BAD_REQUEST",- message: `Poll id in token (${pollId}) did not match: ${input.pollId}`,- });- }-- const poll = await prisma.poll.update({- where: {- id: pollId,- },- data: {- verified: true,- notifications: true,- },- include: { user: true },- });-- // If logged in as guest, we update all participants- // and comments by this guest to the user that we just authenticated- if (ctx.session.user?.isGuest) {- await mergeGuestsIntoUser(poll.user.id, [ctx.session.user.id]);- }-- ctx.session.user = {- id: poll.user.id,- isGuest: false,- };- await ctx.session.save();- }),-});