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.

Added help article for link cloaking

Steven Teyda5d9f14d8a2
diff --git a/app/admin/components/ban.tsx b/app/admin/components/ban.tsx
index f41938d921..447c382d24 100644
--- a/app/admin/components/ban.tsx
+++ b/app/admin/components/ban.tsx
@@ -123,19 +123,14 @@ const Form = () => {
disabled={pending}
autoComplete="off"
onPaste={(e) => {
- const pastedText = e.clipboardData.getData("text");
+ // replace http://dub.sh/ or https://dub.sh/ with nothing
+ const pastedText = e.clipboardData
+ .getData("text")
+ .replace(/https?:\/\/dub\.sh\//, "");
+ e.currentTarget.value = pastedText;
- // Check if the pasted text is a URL that matches the pattern
- if (pastedText.startsWith("https://dub.sh/")) {
- // Extract the part of the URL after 'https://dub.sh/'
- const extractedText = pastedText.replace("https://dub.sh/", "");
-
- // Set the extracted text as the value of the input
- e.currentTarget.value = extractedText;
-
- // Prevent the default paste behavior
- e.preventDefault();
- }
+ // Prevent the default paste behavior
+ e.preventDefault();
}}
className={cn(
"block w-full rounded-r-md border-gray-300 text-sm text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500",
diff --git a/app/admin/components/impersonate-project.tsx b/app/admin/components/impersonate-project.tsx
index edf4b1733f..9cfb86e663 100644
--- a/app/admin/components/impersonate-project.tsx
+++ b/app/admin/components/impersonate-project.tsx
@@ -77,7 +77,6 @@ const Form = () => {
name="slug"
id="slug"
type="text"
- autoFocus
required
disabled={pending}
autoComplete="off"
diff --git a/app/admin/components/impersonate-user.tsx b/app/admin/components/impersonate-user.tsx
index bd107a3003..9c608980d4 100644
--- a/app/admin/components/impersonate-user.tsx
+++ b/app/admin/components/impersonate-user.tsx
@@ -74,7 +74,6 @@ const Form = () => {
name="email"
id="email"
type="email"
- autoFocus
required
disabled={pending}
autoComplete="off"
diff --git a/app/ui/modals/add-edit-link-modal/index.tsx b/app/ui/modals/add-edit-link-modal/index.tsx
index 3eaccd7cfd..7da66294f7 100644
--- a/app/ui/modals/add-edit-link-modal/index.tsx
+++ b/app/ui/modals/add-edit-link-modal/index.tsx
@@ -46,6 +46,7 @@ import va from "@vercel/analytics";
import punycode from "punycode/";
import Button from "#/ui/button";
import { ModalContext } from "#/ui/modal-provider";
+import RewriteSection from "./rewrite-section";
function AddEditLinkModal({
showAddEditLinkModal,
@@ -523,6 +524,7 @@ function AddEditLinkModal({
generatingMetatags={generatingMetatags}
/>
<UTMSection {...{ props, data, setData }} />
+ <RewriteSection {...{ data, setData }} />
<PasswordSection {...{ props, data, setData }} />
<ExpirationSection {...{ props, data, setData }} />
<IOSSection {...{ props, data, setData }} />
diff --git a/app/ui/modals/add-edit-link-modal/rewrite-section.tsx b/app/ui/modals/add-edit-link-modal/rewrite-section.tsx
new file mode 100644
index 0000000000..c82b156374
--- /dev/null
+++ b/app/ui/modals/add-edit-link-modal/rewrite-section.tsx
@@ -0,0 +1,66 @@
+import { Dispatch, SetStateAction, useEffect, useState } from "react";
+import { LinkProps } from "#/lib/types";
+import Switch from "#/ui/switch";
+import { HOME_DOMAIN } from "#/lib/constants";
+import { InfoTooltip, SimpleTooltipContent } from "#/ui/tooltip";
+import { useParams } from "next/navigation";
+
+export default function RewriteSection({
+ data,
+ setData,
+}: {
+ data: LinkProps;
+ setData: Dispatch<SetStateAction<LinkProps>>;
+}) {
+ const { slug } = useParams() as { slug: string };
+
+ const { rewrite } = data;
+ const [enabled, setEnabled] = useState(rewrite);
+ useEffect(() => {
+ if (enabled) {
+ // if enabling, set rewrite to true or props.rewrite
+ setData({
+ ...data,
+ rewrite: true,
+ });
+ } else {
+ // if disabling, set rewrite to false
+ setData({ ...data, rewrite: false });
+ }
+ }, [enabled]);
+
+ return (
+ <div className="border-b border-gray-200 pb-5">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center justify-between space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">Link Cloaking</h2>
+ <InfoTooltip
+ content={
+ <SimpleTooltipContent
+ title="Mask your destination URL so your users only see the short link in the browser address bar."
+ cta="Learn more."
+ href={`${HOME_DOMAIN}/help/article/how-to-create-link#link-cloaking`}
+ />
+ }
+ />
+ </div>
+ <Switch
+ fn={() => setEnabled(!enabled)}
+ checked={enabled}
+ // link cloaking is only available on custom domains
+ {...(slug
+ ? {}
+ : {
+ disabledTooltip: (
+ <SimpleTooltipContent
+ title="You can only use link cloaking on a project with a custom domain."
+ cta="Learn more."
+ href={`${HOME_DOMAIN}/help/article/how-to-create-link#dubsh-links-vs-custom-domain-links`}
+ />
+ ),
+ })}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/app/ui/switch.tsx b/app/ui/switch.tsx
index f7c651f752..19b2afed1c 100644
--- a/app/ui/switch.tsx
+++ b/app/ui/switch.tsx
@@ -1,6 +1,6 @@
"use client";
-import { Dispatch, SetStateAction } from "react";
+import { Dispatch, ReactNode, SetStateAction } from "react";
import * as SwitchPrimitive from "@radix-ui/react-switch";
import { cn } from "#/lib/utils";
import Tooltip from "./tooltip";
@@ -20,7 +20,7 @@ const Switch = ({
thumbTranslate?: string;
checked?: boolean;
disabled?: boolean;
- disabledTooltip?: string;
+ disabledTooltip?: string | ReactNode;
}) => {
if (disabledTooltip) {
return (
diff --git a/app/ui/tooltip.tsx b/app/ui/tooltip.tsx
index e3735061bb..8d724ba9ef 100644
--- a/app/ui/tooltip.tsx
+++ b/app/ui/tooltip.tsx
@@ -112,6 +112,7 @@ export function TooltipContent({
</Link>
) : onClick ? (
<button
+ type="button"
className="mt-4 w-full rounded-md border border-black bg-black px-3 py-1.5 text-center text-sm text-white transition-all hover:bg-white hover:text-black"
onClick={onClick}
>
diff --git a/components/app/modals/add-edit-link-modal/rewrite-section.tsx b/components/app/modals/add-edit-link-modal/rewrite-section.tsx
index 89012bdeef..47160ce252 100644
--- a/components/app/modals/add-edit-link-modal/rewrite-section.tsx
+++ b/components/app/modals/add-edit-link-modal/rewrite-section.tsx
@@ -3,7 +3,7 @@ import { LinkProps } from "#/lib/types";
import Switch from "#/ui/switch";
import { HOME_DOMAIN } from "#/lib/constants";
import { InfoTooltip, SimpleTooltipContent } from "#/ui/tooltip";
-import useProject from "#/lib/swr/use-project";
+import { useRouter } from "next/router";
export default function RewriteSection({
data,
@@ -12,7 +12,9 @@ export default function RewriteSection({
data: LinkProps;
setData: Dispatch<SetStateAction<LinkProps>>;
}) {
- const { plan } = useProject();
+ const router = useRouter();
+ const { slug } = router.query;
+
const { rewrite } = data;
const [enabled, setEnabled] = useState(rewrite);
useEffect(() => {
@@ -38,7 +40,7 @@ export default function RewriteSection({
<SimpleTooltipContent
title="Mask your destination URL so your users only see the short link in the browser address bar."
cta="Learn more."
- href={`${HOME_DOMAIN}/help/article/how-to-create-link#expiration-date`}
+ href={`${HOME_DOMAIN}/help/article/how-to-create-link#link-cloaking`}
/>
}
/>
@@ -46,12 +48,18 @@ export default function RewriteSection({
<Switch
fn={() => setEnabled(!enabled)}
checked={enabled}
- {...(!plan || plan === "free"
- ? {
- disabledTooltip:
- "Link cloaking is only available on paid plans.",
- }
- : {})}
+ // link cloaking is only available on custom domains
+ {...(slug
+ ? {}
+ : {
+ disabledTooltip: (
+ <SimpleTooltipContent
+ title="You can only use link cloaking on a project with a custom domain."
+ cta="Learn more."
+ href={`${HOME_DOMAIN}/help/article/how-to-create-link#dubsh-links-vs-custom-domain-links`}
+ />
+ ),
+ })}
/>
</div>
</div>
diff --git a/content/help/how-to-create-link.mdx b/content/help/how-to-create-link.mdx
index 505d20eae8..5f4487f3a2 100644
--- a/content/help/how-to-create-link.mdx
+++ b/content/help/how-to-create-link.mdx
@@ -38,6 +38,7 @@ Here are the difference between the two options:
| **Dashboard location** | [app.dub.sh/links](https://app.dub.sh/links) | Can be found in the project select menu at the top menu bar |
| **Link history** | 30 days | 30 days - Unlimited ([Pro plan](pro-plan)) |
| **Tags** | Unavailable | Can be used to organize links |
+| **Link cloaking** | Unavailable | Can be used to mask destination URL with your short link |
## The Dub link builder
@@ -61,10 +62,11 @@ Inside the link builder are the following fields:
3. **Choose a tag** (custom domain links only): Choose a tag to organize your links. You can learn more about tags [here](how-to-use-tags).
4. **Custom Social Media Cards**: Customize how your links look when shared on social media. [Learn more](#custom-social-media-cards).
5. **UTM Builder**: Add UTM parameters to your links. [Learn more](#utm-builder).
-6. **Password Protection**: Protect your links with a password. [Learn more](#password-protection).
-7. **Expiration Date**: Set an expiration date for your links. [Learn more](#expiration-date).
-8. **Device Targeting**: Set a custom destination URL for iOS and Android devices. [Learn more](#device-targeting-ios--android).
-9. **Social Previews**: See how your links will look when shared on social media.
+6. **Link Cloaking**: Mask your destination URL with your short link. [Learn more](#link-cloaking).
+7. **Password Protection**: Protect your links with a password. [Learn more](#password-protection).
+8. **Expiration Date**: Set an expiration date for your links. [Learn more](#expiration-date).
+9. **Device Targeting**: Set a custom destination URL for iOS and Android devices. [Learn more](#device-targeting-ios--android).
+10. **Social Previews**: See how your links will look when shared on social media.
## Custom social media cards
@@ -105,6 +107,31 @@ You can use the UTM builder to populate UTM parameters for your links.
height={583}
/>
+## Link cloaking
+
+You can mask your destination URL with your short link by toggling the "Link Cloaking" switch in the link builder.
+
+<Image
+ alt="Toggling the 'Link Cloaking' switch in the link builder"
+ src="https://d2vwwcvoksz7ty.cloudfront.net/help/link-cloaking.png"
+ width={1126}
+ height={478}
+/>
+
+When this is enabled, your short link will be shown in your users' browser address bar when they visit your link instead of the destination URL.
+
+<Image
+ alt="Masking 'youtube.com/@stey' with 'steven.yt'"
+ src="https://d2vwwcvoksz7ty.cloudfront.net/help/rewrite-domain-example.png"
+ width={811}
+ height={525}
+/>
+
+<Note variant="success">
+ This feature is only available for short links created with a [custom
+ domain](how-to-add-custom-domain).
+</Note>
+
## Password protection
You can protect your links with a password by toggling the "Password Protection" switch in the link builder.
diff --git a/content/help/how-to-redirect-root-domain.mdx b/content/help/how-to-redirect-root-domain.mdx
index 414398ad6d..c4de869bdf 100644
--- a/content/help/how-to-redirect-root-domain.mdx
+++ b/content/help/how-to-redirect-root-domain.mdx
@@ -39,7 +39,7 @@ To redirect your domain to a URL of your choice, follow these steps:
In certain cases, you might want to rewrite your domain to a given URL (also known as URL masking or cloaking).
<Image
- alt="Rewriting 'steven.yt' to 'youtube.com/@stey'"
+ alt="Masking 'youtube.com/@stey' with 'steven.yt'"
src="https://d2vwwcvoksz7ty.cloudfront.net/help/rewrite-domain-example.png"
width={811}
height={525}
diff --git a/lib/constants/index.ts b/lib/constants/index.ts
index a9b9fe72f1..2d2ec5aaef 100644
--- a/lib/constants/index.ts
+++ b/lib/constants/index.ts
@@ -37,7 +37,11 @@ export const FADE_IN_ANIMATION_SETTINGS = {
as the callback URL.
*/
-export const HOME_HOSTNAMES = new Set(["home.localhost:8888", "dub.sh"]);
+export const HOME_HOSTNAMES = new Set([
+ "home.localhost:8888",
+ "localhost",
+ "dub.sh",
+]);
export const HOME_DOMAIN =
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
diff --git a/pages/api/links/[key]/index.ts b/pages/api/links/[key]/index.ts
index 1d9b9b3926..9587428f5d 100644
--- a/pages/api/links/[key]/index.ts
+++ b/pages/api/links/[key]/index.ts
@@ -42,14 +42,10 @@ export default withLinksAuth(
if (domainBlacklisted) {
return res.status(422).end("Invalid url.");
}
- }
-
- // free plan limitations
- if (!project || project.plan === "free") {
if (rewrite) {
return res
.status(403)
- .end("Link cloaking is only available for Pro users.");
+ .end("You can only use link cloaking on a custom domain.");
}
}
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index 13a19880a0..59324c69fa 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -57,14 +57,10 @@ export default withLinksAuth(
if (domainBlacklisted) {
return res.status(422).end("Invalid url.");
}
- }
-
- // free plan limitations
- if (!project || project.plan === "free") {
if (rewrite) {
return res
.status(403)
- .end("Link cloaking is only available for Pro users.");
+ .end("You can only use link cloaking on a custom domain.");
}
}