⚰️ Remove dead verification code (#566)

This commit is contained in:
Luke Vella 2023-03-14 22:52:49 +00:00 committed by GitHub
parent 086091b67f
commit 7470cfecdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 97 deletions

View file

@ -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",

View file

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

View file

@ -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 ROUTES
enableNotifications: possiblyPublicProcedure
.input(z.object({ adminUrlId: z.string() }))

View file

@ -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();
}),
});