Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Split workspace environment checks into a client-safe module

Kiran Kdcca3c724877
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discounts/group-discounts.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discounts/group-discounts.tsx
index 2c9ea974f6..6b8f54e3db 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discounts/group-discounts.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/discounts/group-discounts.tsx
@@ -1,7 +1,7 @@
"use client";
import { useCopyDiscountToLiveModal } from "@/lib/sandbox/components/copy-discount-to-live-modal";
-import { isStagingEnvironment } from "@/lib/sandbox/workspace-guards";
+import { isStagingEnvironment } from "@/lib/sandbox/environment";
import useGroup from "@/lib/swr/use-group";
import useWorkspace from "@/lib/swr/use-workspace";
import type { DiscountProps, GroupProps } from "@/lib/types";
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx
index 59d9cf9751..ce1378dd77 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/[groupSlug]/rewards/group-rewards.tsx
@@ -2,7 +2,7 @@
import { getPlanCapabilities } from "@/lib/plan-capabilities";
import { useCopyRewardToLiveModal } from "@/lib/sandbox/components/copy-reward-to-live-modal";
-import { isStagingEnvironment } from "@/lib/sandbox/workspace-guards";
+import { isStagingEnvironment } from "@/lib/sandbox/environment";
import useGroup from "@/lib/swr/use-group";
import useWorkspace from "@/lib/swr/use-workspace";
import type { GroupProps, RewardProps } from "@/lib/types";
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page.tsx
index 9b20214830..0129875d8b 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/members/page.tsx
@@ -2,7 +2,7 @@
import { clientAccessCheck } from "@/lib/client-access-check";
import { exceededLimitError } from "@/lib/exceeded-limit-error";
-import { isStagingEnvironment } from "@/lib/sandbox/workspace-guards";
+import { isStagingEnvironment } from "@/lib/sandbox/environment";
import useWorkspace from "@/lib/swr/use-workspace";
import useWorkspaceUsers from "@/lib/swr/use-workspace-users";
import { WorkspaceUserProps } from "@/lib/types";
diff --git a/apps/web/lib/hooks/use-dashboard-banner-visible.ts b/apps/web/lib/hooks/use-dashboard-banner-visible.ts
index 89bfdfd7f6..f79e104589 100644
--- a/apps/web/lib/hooks/use-dashboard-banner-visible.ts
+++ b/apps/web/lib/hooks/use-dashboard-banner-visible.ts
@@ -1,6 +1,6 @@
"use client";
-import { isProductionEnvironment } from "@/lib/sandbox/workspace-guards";
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
import useWorkspace from "@/lib/swr/use-workspace";
export function useDashboardBannerVisible() {
diff --git a/apps/web/lib/sandbox/components/workspace-environment.tsx b/apps/web/lib/sandbox/components/workspace-environment.tsx
index 17f0be958a..691f287ee8 100644
--- a/apps/web/lib/sandbox/components/workspace-environment.tsx
+++ b/apps/web/lib/sandbox/components/workspace-environment.tsx
@@ -13,7 +13,7 @@ import { usePathname } from "next/navigation";
import {
isProductionEnvironment,
isStagingEnvironment,
-} from "../workspace-guards";
+} from "../environment";
const buttonClassName =
"text-content-emphasis flex w-full items-center justify-center gap-x-2 rounded-lg border border-neutral-200 px-2 py-1 outline-none transition-all duration-75 hover:bg-neutral-100/50 focus-visible:ring-2 focus-visible:ring-black/50 active:bg-neutral-200/80";
diff --git a/apps/web/lib/sandbox/environment.ts b/apps/web/lib/sandbox/environment.ts
new file mode 100644
index 0000000000..00d55878f4
--- /dev/null
+++ b/apps/web/lib/sandbox/environment.ts
@@ -0,0 +1,18 @@
+// Client-safe environment checks. Kept separate from workspace-guards.ts because
+// that module throws DubApiError from @/lib/api/errors (server-only), which
+// breaks client components that only need these helpers.
+import { WorkspaceEnvironment } from "@prisma/client";
+
+export function isStagingEnvironment(
+ environment: WorkspaceEnvironment | null | undefined,
+) {
+ return Boolean(environment && environment === WorkspaceEnvironment.staging);
+}
+
+export function isProductionEnvironment(
+ environment: WorkspaceEnvironment | null | undefined,
+) {
+ return Boolean(
+ environment && environment === WorkspaceEnvironment.production,
+ );
+}
diff --git a/apps/web/lib/sandbox/workspace-guards.ts b/apps/web/lib/sandbox/workspace-guards.ts
index 0136f70203..a505693df8 100644
--- a/apps/web/lib/sandbox/workspace-guards.ts
+++ b/apps/web/lib/sandbox/workspace-guards.ts
@@ -1,5 +1,11 @@
import { DubApiError } from "@/lib/api/errors";
-import { Project, WorkspaceEnvironment } from "@prisma/client";
+import {
+ isProductionEnvironment,
+ isStagingEnvironment,
+} from "@/lib/sandbox/environment";
+import { Project } from "@prisma/client";
+
+export { isProductionEnvironment, isStagingEnvironment };
export function assertStagingWorkspace(
workspace: Pick<Project, "environment">,
@@ -57,17 +63,3 @@ export function assertProductionWorkspace(
});
}
}
-
-export function isStagingEnvironment(
- environment: WorkspaceEnvironment | null | undefined,
-) {
- return Boolean(environment && environment === WorkspaceEnvironment.staging);
-}
-
-export function isProductionEnvironment(
- environment: WorkspaceEnvironment | null | undefined,
-) {
- return Boolean(
- environment && environment === WorkspaceEnvironment.production,
- );
-}
diff --git a/apps/web/ui/layout/sidebar/workspace-dropdown.tsx b/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
index 49ccce08f1..5534310d7d 100644
--- a/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
+++ b/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
@@ -1,7 +1,7 @@
"use client";
import { WorkspaceEnvironmentSwitcher } from "@/lib/sandbox/components/workspace-environment";
-import { isStagingEnvironment } from "@/lib/sandbox/workspace-guards";
+import { isStagingEnvironment } from "@/lib/sandbox/environment";
import useWorkspaceUsers from "@/lib/swr/use-workspace-users";
import useWorkspaces from "@/lib/swr/use-workspaces";
import { PlanProps, WorkspaceProps } from "@/lib/types";