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.

fix #707

Steven Teyda66b8d691bb
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index 2714061db3..4632178e9b 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -212,6 +212,22 @@ export async function keyChecks({
key: string;
workspace?: WorkspaceProps;
}) {
+ if (key.length === 0) {
+ if (workspace?.plan === "free") {
+ return {
+ error:
+ "You can only set a redirect for your root domain on a Pro plan and above. Upgrade to Pro to unlock this feature.",
+ code: "forbidden",
+ };
+ } else {
+ return {
+ error:
+ "To set a redirect for your root domain, navigate to your Domains tab and click 'Edit' on the domain you want to update.",
+ code: "unprocessable_entity",
+ };
+ }
+ }
+
const link = await checkIfKeyExists(domain, key);
if (link) {
return {
@@ -259,9 +275,6 @@ export function processKey(key: string) {
}
// remove all leading and trailing slashes from key
key = key.replace(/^\/+|\/+$/g, "");
- if (key.length === 0) {
- return null;
- }
// replace all special characters
key = key.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
@@ -378,7 +391,7 @@ export async function processLink({
key = await getRandomKey(domain, payload["prefix"]);
} else if (!skipKeyChecks) {
const processedKey = processKey(key);
- if (!processedKey) {
+ if (processedKey === null) {
return {
link: payload,
error: "Invalid key.",
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index 09210f5e53..bea3a7e7de 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -369,9 +369,10 @@ function AddEditLinkModal({
const { error } = await res.json();
if (error) {
toast.error(error.message);
- if (error.message.toLowerCase().includes("key")) {
+ const message = error.message.toLowerCase();
+ if (message.includes("key") || message.includes("domain")) {
setKeyError(error.message);
- } else if (error.message.toLowerCase().includes("url")) {
+ } else if (message.includes("url")) {
setUrlError(error.message);
}
}