Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unprotected Welcome Route Allows Users with Dataroom Plans to Start Trials Without Restrictions #1348

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions pages/welcome.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useRouter } from "next/router";

import { useEffect, useRef } from "react";

import { AnimatePresence } from "framer-motion";
import { ArrowLeft as ArrowLeftIcon } from "lucide-react";
import { toast } from "sonner";

import { Button } from "@/components/ui/button";
import Dataroom from "@/components/welcome/dataroom";
Expand All @@ -13,9 +16,12 @@ import NotionForm from "@/components/welcome/notion-form";
import Select from "@/components/welcome/select";
import Upload from "@/components/welcome/upload";

import { usePlan } from "@/lib/swr/use-billing";

export default function Welcome() {
const router = useRouter();

const { plan, trial } = usePlan();
const toastShownRef = useRef(false);
const isDataroomUpload = router.query.type === "dataroom-upload";

const skipButtonText = isDataroomUpload
Expand All @@ -26,6 +32,20 @@ export default function Welcome() {
? `/datarooms/${router.query.dataroomId}`
: "/documents";

if (
router?.query?.type?.includes("dataroom") &&
plan &&
!plan.includes("free")
) {
if (!toastShownRef.current) {
toast.info(`You already have a ${plan} ${trial && "trial "}plan`);
toastShownRef.current = true;
}

router.replace("/documents");
return <></>;
}

return (
<div className="mx-auto flex h-screen max-w-3xl flex-col items-center justify-center overflow-x-hidden">
<div
Expand All @@ -52,7 +72,10 @@ export default function Welcome() {

<Button
variant={"link"}
onClick={() => router.push(skipButtonPath)}
onClick={(e) => {
e.preventDefault();
router.push(skipButtonPath);
}}
className="absolute right-2 top-10 z-40 p-2 text-muted-foreground sm:right-10"
>
{skipButtonText}
Expand Down
Loading