mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-06 09:59:00 +02:00
⚰️ Remove dead verification code (#566)
This commit is contained in:
parent
086091b67f
commit
7470cfecdf
4 changed files with 1 additions and 97 deletions
|
@ -53,7 +53,6 @@
|
||||||
"hide": "Hide",
|
"hide": "Hide",
|
||||||
"home": "Home",
|
"home": "Home",
|
||||||
"ifNeedBe": "If need be",
|
"ifNeedBe": "If need be",
|
||||||
"linkHasExpired": "Your link has expired or is no longer valid",
|
|
||||||
"loading": "Loading…",
|
"loading": "Loading…",
|
||||||
"loadingParticipants": "Loading participants…",
|
"loadingParticipants": "Loading participants…",
|
||||||
"location": "Location",
|
"location": "Location",
|
||||||
|
@ -104,7 +103,6 @@
|
||||||
"participantCount_two": "{{count}} participants",
|
"participantCount_two": "{{count}} participants",
|
||||||
"participantCount_zero": "{{count}} participants",
|
"participantCount_zero": "{{count}} participants",
|
||||||
"pollHasBeenLocked": "This poll has been locked",
|
"pollHasBeenLocked": "This poll has been locked",
|
||||||
"pollHasBeenVerified": "Your poll has been verified",
|
|
||||||
"pollOwnerNotice": "Hey {{name}}, looks like you are the owner of this poll.",
|
"pollOwnerNotice": "Hey {{name}}, looks like you are the owner of this poll.",
|
||||||
"pollsEmpty": "No polls created",
|
"pollsEmpty": "No polls created",
|
||||||
"possibleAnswers": "Possible answers",
|
"possibleAnswers": "Possible answers",
|
||||||
|
|
|
@ -4,30 +4,23 @@ import { useTranslation } from "next-i18next";
|
||||||
import posthog from "posthog-js";
|
import posthog from "posthog-js";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { useMount } from "react-use";
|
|
||||||
|
|
||||||
import { Button } from "@/components/button";
|
import { Button } from "@/components/button";
|
||||||
import Share from "@/components/icons/share.svg";
|
import Share from "@/components/icons/share.svg";
|
||||||
|
|
||||||
import { trpc } from "../utils/trpc";
|
|
||||||
import { useParticipants } from "./participants-provider";
|
import { useParticipants } from "./participants-provider";
|
||||||
import ManagePoll from "./poll/manage-poll";
|
import ManagePoll from "./poll/manage-poll";
|
||||||
import { useUpdatePollMutation } from "./poll/mutations";
|
import { useUpdatePollMutation } from "./poll/mutations";
|
||||||
import NotificationsToggle from "./poll/notifications-toggle";
|
import NotificationsToggle from "./poll/notifications-toggle";
|
||||||
import { usePoll } from "./poll-context";
|
import { usePoll } from "./poll-context";
|
||||||
import Sharing from "./sharing";
|
import Sharing from "./sharing";
|
||||||
import { useUser } from "./user-provider";
|
|
||||||
|
|
||||||
export const AdminControls = (props: { children?: React.ReactNode }) => {
|
export const AdminControls = (props: { children?: React.ReactNode }) => {
|
||||||
const { poll, urlId } = usePoll();
|
const { urlId } = usePoll();
|
||||||
const { t } = useTranslation("app");
|
const { t } = useTranslation("app");
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const queryClient = trpc.useContext();
|
|
||||||
|
|
||||||
const session = useUser();
|
|
||||||
|
|
||||||
const { mutate: updatePollMutation } = useUpdatePollMutation();
|
const { mutate: updatePollMutation } = useUpdatePollMutation();
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
@ -47,37 +40,12 @@ export const AdminControls = (props: { children?: React.ReactNode }) => {
|
||||||
}
|
}
|
||||||
}, [urlId, router, updatePollMutation, t]);
|
}, [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 { participants } = useParticipants();
|
||||||
|
|
||||||
const [isSharingVisible, setIsSharingVisible] = React.useState(
|
const [isSharingVisible, setIsSharingVisible] = React.useState(
|
||||||
participants.length === 0,
|
participants.length === 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
useMount(() => {
|
|
||||||
const { code } = router.query;
|
|
||||||
if (typeof code === "string" && !poll.verified) {
|
|
||||||
verifyEmail.mutate({ code, pollId: poll.id });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="">
|
<div className="">
|
||||||
<div className="mb-3 flex justify-end sm:mb-4">
|
<div className="mb-3 flex justify-end sm:mb-4">
|
||||||
|
|
|
@ -12,7 +12,6 @@ import { possiblyPublicProcedure, publicProcedure, router } from "../trpc";
|
||||||
import { comments } from "./polls/comments";
|
import { comments } from "./polls/comments";
|
||||||
import { demo } from "./polls/demo";
|
import { demo } from "./polls/demo";
|
||||||
import { participants } from "./polls/participants";
|
import { participants } from "./polls/participants";
|
||||||
import { verification } from "./polls/verification";
|
|
||||||
|
|
||||||
const defaultSelectFields: {
|
const defaultSelectFields: {
|
||||||
id: true;
|
id: true;
|
||||||
|
@ -251,7 +250,6 @@ export const polls = router({
|
||||||
demo,
|
demo,
|
||||||
participants,
|
participants,
|
||||||
comments,
|
comments,
|
||||||
verification,
|
|
||||||
// END LEGACY ROUTES
|
// END LEGACY ROUTES
|
||||||
enableNotifications: possiblyPublicProcedure
|
enableNotifications: possiblyPublicProcedure
|
||||||
.input(z.object({ adminUrlId: z.string() }))
|
.input(z.object({ adminUrlId: z.string() }))
|
||||||
|
|
|
@ -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();
|
|
||||||
}),
|
|
||||||
});
|
|
Loading…
Add table
Add a link
Reference in a new issue