Skip to content

Commit 3625d70

Browse files
authored
fix: bypass custom URL checkout for self hosted (#16)
* fix: bypass custom URL checkout for self hosted * Update error code
1 parent 2047f5a commit 3625d70

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

apps/web/public/__ENV.js

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/web/src/views/settings/components/UpdateWorkspaceUrlForm.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { zodResolver } from "@hookform/resolvers/zod";
2+
import { env } from "next-runtime-env";
23
import { useForm } from "react-hook-form";
34
import { HiCheck, HiMiniStar } from "react-icons/hi2";
45
import { z } from "zod";
@@ -92,7 +93,9 @@ const UpdateWorkspaceUrlForm = ({
9293
const isWorkspaceSlugAvailable = checkWorkspaceSlugAvailability.data;
9394

9495
const onSubmit = (data: FormValues) => {
95-
if (isWorkspaceSlugAvailable?.isAvailable && workspacePlan !== "pro")
96+
if (!isWorkspaceSlugAvailable?.isAvailable) return;
97+
98+
if (workspacePlan !== "pro" && env("NEXT_PUBLIC_KAN_ENV") === "cloud")
9699
return openModal("UPDATE_WORKSPACE_URL", data.slug);
97100

98101
updateWorkspaceSlug.mutate({
@@ -118,7 +121,11 @@ const UpdateWorkspaceUrlForm = ({
118121
? "This workspace username has already been taken"
119122
: undefined)
120123
}
121-
prefix="kan.bn/"
124+
prefix={
125+
env("NEXT_PUBLIC_KAN_ENV") === "cloud"
126+
? "kan.bn/"
127+
: `${env("NEXT_PUBLIC_BASE_URL")}/`
128+
}
122129
iconRight={
123130
isWorkspaceSlugAvailable?.isAvailable ||
124131
(workspacePlan === "pro" && slug === workspaceUrl) ? (

packages/api/src/routers/workspace.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TRPCError } from "@trpc/server";
2+
import { env } from "next-runtime-env";
23
import { z } from "zod";
34

45
import * as workspaceRepo from "@kan/db/repository/workspace.repo";
@@ -224,10 +225,19 @@ export const workspaceRouter = createTRPCRouter({
224225
const isWorkspaceSlugAvailable =
225226
await workspaceRepo.isWorkspaceSlugAvailable(ctx.db, input.slug);
226227

228+
if (
229+
env("NEXT_PUBLIC_KAN_ENV") === "cloud" &&
230+
workspace.plan !== "pro" &&
231+
input.slug !== workspace.publicId
232+
) {
233+
throw new TRPCError({
234+
message: `Workspace slug cannot be changed in cloud without upgrading to a paid plan`,
235+
code: "FORBIDDEN",
236+
});
237+
}
238+
227239
if (
228240
reservedOrPremiumWorkspaceSlug?.type === "reserved" ||
229-
(workspace.plan !== "pro" &&
230-
reservedOrPremiumWorkspaceSlug?.type === "premium") ||
231241
!isWorkspaceSlugAvailable
232242
) {
233243
throw new TRPCError({

0 commit comments

Comments
 (0)