Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
Enable token page for teams with the tokens feature flag
Marc Seitzcd374a9aa863
diff --git a/components/settings/settings-header.tsx b/components/settings/settings-header.tsxindex d87a1359..49fdb3b7 100644--- a/components/settings/settings-header.tsx+++ b/components/settings/settings-header.tsx@@ -8,7 +8,7 @@ export function SettingsHeader() {const { features } = useFeatureFlags();const { isAdmin } = useIsAdmin();const { isDatarooms, isTrial } = usePlan();- const hasTokensAccess = isDatarooms || isTrial;+ const hasTokensAccess = isDatarooms || isTrial || !!features?.tokens;return (<header>diff --git a/pages/api/teams/[teamId]/tokens/index.ts b/pages/api/teams/[teamId]/tokens/index.tsindex 6d9059cb..c678ba5b 100644--- a/pages/api/teams/[teamId]/tokens/index.ts+++ b/pages/api/teams/[teamId]/tokens/index.ts@@ -8,6 +8,7 @@ import {parseRestrictedTokenSubjectType,} from "@/lib/api/auth/restricted-tokens";import { hashToken } from "@/lib/api/auth/token";+import { getFeatureFlags } from "@/lib/featureFlags";import { newId } from "@/lib/id-helper";import { GRANULAR_SCOPES, PRESET_SCOPES } from "@/lib/oauth/scopes";import prisma from "@/lib/prisma";@@ -35,14 +36,20 @@ export default async function handle(return res.status(403).json({ error: "Unauthorized" });}- // Tokens require a Data Rooms plan or higher (or a Data Rooms trial).+ // Tokens require a Data Rooms plan or higher (or a Data Rooms trial), or the+ // `tokens` beta feature flag enabled for the team. Only hit Edge Config for+ // the flag when the plan check fails, so paid teams skip that latency.const team = await prisma.team.findUnique({where: { id: teamId },select: { plan: true },});const plan = team?.plan ?? "";- const hasTokensAccess =+ let hasTokensAccess =plan.includes("datarooms") || plan.includes("drtrial");+ if (!hasTokensAccess) {+ const features = await getFeatureFlags({ teamId });+ hasTokensAccess = Boolean(features.tokens);+ }if (!hasTokensAccess) {return res.status(403)diff --git a/pages/settings/tokens.tsx b/pages/settings/tokens.tsxindex 3c1b1fff..85cbdcc5 100644--- a/pages/settings/tokens.tsx+++ b/pages/settings/tokens.tsx@@ -14,6 +14,7 @@ import {import { toast } from "sonner";import useSWR from "swr";+import { useFeatureFlags } from "@/lib/hooks/use-feature-flags";import { usePlan } from "@/lib/swr/use-billing";import { cn, fetcher, timeAgo } from "@/lib/utils";@@ -64,16 +65,18 @@ export default function TokenSettings() {const router = useRouter();const { isDatarooms, isTrial, loading: planLoading } = usePlan();- const hasTokensAccess = isDatarooms || isTrial;+ const { features, isLoading: featuresLoading } = useFeatureFlags();+ const hasTokensAccess = isDatarooms || isTrial || !!features?.tokens;useEffect(() => {- // `planLoading` is only meaningful once we have a teamId.- if (!teamId || planLoading) return;+ // `planLoading` is only meaningful once we have a teamId. Wait for the+ // feature flags too so we don't redirect a flag-enabled team prematurely.+ if (!teamId || planLoading || featuresLoading) return;if (!hasTokensAccess) {router.push("/settings/general");toast.error("This feature requires a Data Rooms plan or higher");}- }, [teamId, planLoading, hasTokensAccess, router]);+ }, [teamId, planLoading, featuresLoading, hasTokensAccess, router]);const {data: tokens,