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 password protection for links :lock:

Steven Tey21f1e04e5d30
diff --git a/README.md b/README.md
index a70dd548d7..2d74a09edc 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@
## Introduction
-Dub is an open-source link shortener with built-in analytics + free custom domains. Built with [Vercel Edge Functions](http://vercel.com/edge) and [Upstash Redis](https://docs.upstash.com/redis).
+Dub is an open-source link shortener with built-in analytics + free custom domains. Built with [Vercel Edge Functions](http://vercel.com/edge), [Upstash Redis](https://docs.upstash.com/redis), and [Planetscale MySQL](https://planetscale.com/).
Here are some of the features that Dub provides out-of-the-box:
@@ -57,7 +57,8 @@ You can deploy your own hosted version of Dub for greater privacy & control. Jus
- [Next.js](https://nextjs.org/) – framework
- [Typescript](https://www.typescriptlang.org/) – language
- [Tailwind](https://tailwindcss.com/) – CSS
-- [Upstash](https://upstash.com/) – database
+- [Upstash](https://upstash.com/) – redis
+- [Planetscale](https://planetscale.com/) – database
- [NextAuth.js](https://next-auth.js.org/) – auth
- [Vercel](https://vercel.com/) – hosting
- [Stripe](https://stripe.com/) – payments
@@ -66,13 +67,14 @@ You can deploy your own hosted version of Dub for greater privacy & control. Jus
Dub is built as a standard Next.js application with [Middleware](https://nextjs.org/docs/advanced-features/middleware) to handle multi-tenancy, inspired by [the Vercel Platforms Starter Kit](https://github.com/vercel/platforms).
-[Redis](https://redis.io/) is used as the database for storing links and analytics data, which works well for key-value data types. Redis also has the Sorted Set data type, which is perfect for storing & retrieving time-series analytics data. Here's the full schema:
+[Redis](https://redis.io/) is used as the caching layer for all short links. Redis also has the Sorted Set data type, which is perfect for storing & retrieving time-series analytics data. Here's the full schema:
-- `{hostname}:links` – hashmap of all links for a given hostname (e.g. `dub.sh:links`)
-- `{hostname}:links:timestamps` – sorted set of all link timestamps for a given hostname (e.g. `dub.sh:links:timestamps`)
-- `{hostname}:clicks:{linkId}` – sorted set of all clicks for a given link (e.g. `dub.sh:clicks:github`)
+- `{hostname}:{key}` – string containing a JSON object with the target URL and password (optional). Also has an optional TTL.
+- `{hostname}:clicks:{key}` – sorted set of all clicks for a given link (e.g. `dub.sh:clicks:github`)
- `{hostname}:root:clicks` – sorted set of all root link clicks for a given hostname (e.g. `dub.sh:root:clicks`)
+[MySQL](https://www.mysql.com/) is used as the database for storing user data, project data, and link metadata. You can refer to the Prisma schema [here](/prisma/schema.prisma).
+
## Contributing
We love our contributors! Here's how you can contribute:
diff --git a/components/app/modals/delete-link-modal.tsx b/components/app/modals/delete-link-modal.tsx
index dfbe1bc47a..4b83153475 100644
--- a/components/app/modals/delete-link-modal.tsx
+++ b/components/app/modals/delete-link-modal.tsx
@@ -3,7 +3,6 @@ import {
Dispatch,
SetStateAction,
useCallback,
- useEffect,
useMemo,
useState,
} from "react";
diff --git a/components/layout/meta.tsx b/components/layout/meta.tsx
index d31aa1cac8..e5e69e25ef 100644
--- a/components/layout/meta.tsx
+++ b/components/layout/meta.tsx
@@ -1,6 +1,5 @@
import Head from "next/head";
-
-const faviconFolder = "/static/favicons";
+import { FAVICON_FOLDER } from "@/lib/constants";
export default function Meta() {
return (
@@ -13,24 +12,24 @@ export default function Meta() {
<link
rel="apple-touch-icon"
sizes="180x180"
- href={`${faviconFolder}/apple-touch-icon.png`}
+ href={`${FAVICON_FOLDER}/apple-touch-icon.png`}
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
- href={`${faviconFolder}/favicon-32x32.png`}
+ href={`${FAVICON_FOLDER}/favicon-32x32.png`}
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
- href={`${faviconFolder}/favicon-16x16.png`}
+ href={`${FAVICON_FOLDER}/favicon-16x16.png`}
/>
<link rel="manifest" href="/site.webmanifest" />
<link
rel="mask-icon"
- href={`${faviconFolder}/safari-pinned-tab.svg`}
+ href={`${FAVICON_FOLDER}/safari-pinned-tab.svg`}
color="#5bbad5"
/>
<meta name="msapplication-TileColor" content="#ffffff" />
diff --git a/lib/constants.ts b/lib/constants.ts
index 90538da592..cc26e72cd2 100644
--- a/lib/constants.ts
+++ b/lib/constants.ts
@@ -26,6 +26,7 @@ export const RESERVED_KEYS = new Set([
"static",
"stats",
"proxy",
+ "auth",
"pricing",
"about",
"placeholder",
@@ -56,6 +57,8 @@ export const DEFAULT_REDIRECTS = {
export const FREE_PLAN_PROJECT_LIMIT = 5;
+export const FAVICON_FOLDER = "/static/favicons";
+
export const COUNTRIES: { [key: string]: string } = {
AF: "Afghanistan",
AL: "Albania",
diff --git a/lib/middleware/link.ts b/lib/middleware/link.ts
index d4bf57d756..1da458fcff 100644
--- a/lib/middleware/link.ts
+++ b/lib/middleware/link.ts
@@ -14,21 +14,24 @@ export default async function LinkMiddleware(
return NextResponse.next();
}
- const response = await redis.hget<Omit<LinkProps, "key">>(
- `${hostname}:links`,
- key,
+ const response = await redis.get<{ url: string; password?: boolean }>(
+ `${hostname}:${key}`,
);
- const { url: target, description, image } = response || {};
+ const { url: target, password } = response || {};
if (target) {
- const isBot = detectBot(req);
+ if (password) {
+ return NextResponse.rewrite(`https://dub.sh/auth/${hostname}/${key}`);
+ }
// special case for link health monitoring with planetfall.io :)
- const noTrack = req.headers.get("dub-no-track");
- if (!noTrack) ev.waitUntil(recordClick(hostname, req, key)); // track the click only if there is no `dub-no-track` header
+ if (!req.headers.get("dub-no-track")) {
+ ev.waitUntil(recordClick(hostname, req, key)); // track the click only if there is no `dub-no-track` header
+ }
+ const isBot = detectBot(req);
if (isBot) {
- // rewrite to proxy page (dub.sh/proxy/[domain]/[key])
+ // rewrite to proxy page (dub.sh/proxy/[domain]/[key]) if it's a bot
return NextResponse.rewrite(`https://dub.sh/proxy/${hostname}/${key}`);
} else {
return NextResponse.redirect(target);
diff --git a/package.json b/package.json
index d9b399468d..96e9c8c956 100644
--- a/package.json
+++ b/package.json
@@ -30,6 +30,7 @@
"@visx/responsive": "^2.10.0",
"@visx/shape": "^2.12.2",
"@visx/tooltip": "^2.10.0",
+ "bcrypt": "^5.1.0",
"cloudinary": "^1.32.0",
"cobe": "^0.6.2",
"focus-trap-react": "^10.0.0",
diff --git a/pages/api/auth/decrypt-password.ts b/pages/api/auth/decrypt-password.ts
new file mode 100644
index 0000000000..09a219a20a
--- /dev/null
+++ b/pages/api/auth/decrypt-password.ts
@@ -0,0 +1,25 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { compare } from "bcrypt";
+import prisma from "@/lib/prisma";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "POST") {
+ const { domain, key, password } = req.body;
+ const { url, passwordHash } = await prisma.link.findUnique({
+ where: { domain_key: { domain, key } },
+ select: { url: true, passwordHash: true },
+ });
+ const validPassword = await compare(password, passwordHash);
+ if (validPassword) {
+ return res.status(200).json({ url });
+ } else {
+ return res.status(401).json({ error: "Invalid password" });
+ }
+ } else {
+ res.setHeader("Allow", ["POST"]);
+ return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
+ }
+}
diff --git a/pages/app/login.tsx b/pages/app/login.tsx
index 801d8e7389..0bd72aa0a5 100644
--- a/pages/app/login.tsx
+++ b/pages/app/login.tsx
@@ -2,6 +2,7 @@ import Link from "next/link";
import { useState } from "react";
import { signIn } from "next-auth/react";
import Meta from "@/components/layout/meta";
+import BlurImage from "@/components/shared/blur-image";
import { LoadingDots } from "@/components/shared/icons";
export default function Login() {
@@ -13,11 +14,22 @@ export default function Login() {
return (
<div className="h-screen w-screen flex justify-center items-center bg-gray-50">
<Meta />
- <div className="flex flex-col space-y-4 w-full max-w-md py-12 px-4 sm:px-16 overflow-hidden text-center align-middle transition-all transform bg-white shadow-xl rounded-2xl">
- <h1 className="font-bold font-display text-3xl">Sign In</h1>
- <p className="text-gray-600 text-sm">
- Use your email address to sign in.
- </p>
+ <div className="w-full max-w-md shadow-xl rounded-2xl border border-gray-100 overflow-hidden">
+ <div className="flex flex-col justify-center items-center space-y-3 text-center sm:px-16 px-4 pt-8 py-6 border-b border-gray-200 bg-white">
+ <a href="https://dub.sh">
+ <BlurImage
+ src="/static/logo.png"
+ alt="Dub.sh logo"
+ className="w-10 h-10 rounded-full"
+ width={20}
+ height={20}
+ />
+ </a>
+ <h3 className="font-semibold text-xl">Sign In</h3>
+ <p className="text-sm text-gray-500">
+ Use your email address to sign in.
+ </p>
+ </div>
<form
onSubmit={async (e) => {
e.preventDefault();
@@ -46,20 +58,26 @@ export default function Login() {
}
});
}}
- className="mt-5 flex flex-col space-y-4"
+ className="flex flex-col space-y-4 bg-gray-50 sm:px-16 px-4 py-8"
>
- <input
- name="email"
- type="email"
- placeholder="Email Address"
- autoComplete="email"
- required
- onChange={(e) => {
- setNoSuchAccount(false);
- setEmail(e.target.value);
- }}
- className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-black focus:border-black sm:text-sm"
- />
+ <div>
+ <label htmlFor="email" className="block text-xs text-gray-600">
+ EMAIL ADDRESS
+ </label>
+ <input
+ id="email"
+ name="email"
+ type="email"
+ placeholder="Email Address"
+ autoComplete="email"
+ required
+ onChange={(e) => {
+ setNoSuchAccount(false);
+ setEmail(e.target.value);
+ }}
+ className="mt-1 appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-black focus:border-black sm:text-sm"
+ />
+ </div>
<button
disabled={signInClicked}
className={`${
@@ -74,24 +92,24 @@ export default function Login() {
<p>{buttonText}</p>
)}
</button>
+ {noSuchAccount ? (
+ <p className="text-red-500 text-center text-sm">
+ No such account.{" "}
+ <Link href="/register">
+ <a className="text-red-600 font-semibold">Sign up</a>
+ </Link>{" "}
+ instead?
+ </p>
+ ) : (
+ <p className="text-gray-600 text-center text-sm">
+ Don't have an account?{" "}
+ <Link href="/register">
+ <a className="text-gray-800 font-semibold">Sign up</a>
+ </Link>{" "}
+ for free.
+ </p>
+ )}
</form>
- {noSuchAccount ? (
- <p className="text-red-500 text-sm">
- No such account.{" "}
- <Link href="/register">
- <a className="text-red-600 font-semibold">Sign up</a>
- </Link>{" "}
- instead?
- </p>
- ) : (
- <p className="text-gray-600 text-sm">
- Don't have an account?{" "}
- <Link href="/register">
- <a className="text-gray-800 font-semibold">Sign up</a>
- </Link>{" "}
- for free.
- </p>
- )}
</div>
</div>
);
diff --git a/pages/app/register.tsx b/pages/app/register.tsx
index 86654c469f..de7d887510 100644
--- a/pages/app/register.tsx
+++ b/pages/app/register.tsx
@@ -2,6 +2,7 @@ import Link from "next/link";
import { useState } from "react";
import { signIn } from "next-auth/react";
import Meta from "@/components/layout/meta";
+import BlurImage from "@/components/shared/blur-image";
import { LoadingDots } from "@/components/shared/icons";
export default function Login() {
@@ -13,11 +14,20 @@ export default function Login() {
return (
<div className="h-screen w-screen flex justify-center items-center bg-gray-50">
<Meta />
- <div className="flex flex-col space-y-4 w-full max-w-md py-12 px-4 sm:px-16 overflow-hidden text-center align-middle transition-all transform bg-white shadow-xl rounded-2xl">
- <h1 className="font-bold font-display text-3xl">Sign Up</h1>
- <p className="text-gray-600 text-sm">
- Get started for free. No credit card required.
- </p>
+ <div className="w-full max-w-md shadow-xl rounded-2xl border border-gray-100 overflow-hidden">
+ <div className="flex flex-col justify-center items-center space-y-3 text-center sm:px-16 px-4 pt-8 py-6 border-b border-gray-200 bg-white">
+ <BlurImage
+ src="/static/logo.png"
+ alt="Dub.sh logo"
+ className="w-10 h-10 rounded-full"
+ width={20}
+ height={20}
+ />
+ <h3 className="font-semibold text-xl">Sign Up</h3>
+ <p className="text-sm text-gray-500">
+ Get started for free. No credit card required.
+ </p>
+ </div>
<form
onSubmit={async (e) => {
e.preventDefault();
@@ -46,20 +56,26 @@ export default function Login() {
}
});
}}
- className="mt-5 flex flex-col space-y-4"
+ className="flex flex-col space-y-4 bg-gray-50 sm:px-16 px-4 py-8"
>
- <input
- name="email"
- type="email"
- placeholder="Email Address"
- autoComplete="email"
- required
- onChange={(e) => {
- setAccountExists(false);
- setEmail(e.target.value);
- }}
- className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-black focus:border-black sm:text-sm"
- />
+ <div>
+ <label htmlFor="email" className="block text-xs text-gray-600">
+ EMAIL ADDRESS
+ </label>
+ <input
+ id="email"
+ name="email"
+ type="email"
+ placeholder="[email protected]"
+ autoComplete="email"
+ required
+ onChange={(e) => {
+ setAccountExists(false);
+ setEmail(e.target.value);
+ }}
+ className="mt-1 appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-black focus:border-black sm:text-sm"
+ />
+ </div>
<button
disabled={signInClicked}
className={`${
@@ -74,24 +90,24 @@ export default function Login() {
<p>{buttonText}</p>
)}
</button>
+ {accountExists ? (
+ <p className="text-red-500 text-center text-sm">
+ This email is already registered.{" "}
+ <Link href="/login">
+ <a className="text-red-600 font-semibold">Log in</a>
+ </Link>{" "}
+ instead?
+ </p>
+ ) : (
+ <p className="text-gray-600 text-center text-sm">
+ Already registered?{" "}
+ <Link href="/login">
+ <a className="text-gray-800 font-semibold">Sign in</a>
+ </Link>{" "}
+ to your account.
+ </p>
+ )}
</form>
- {accountExists ? (
- <p className="text-red-500 text-sm">
- This email is already registered.{" "}
- <Link href="/login">
- <a className="text-red-600 font-semibold">Log in</a>
- </Link>{" "}
- instead?
- </p>
- ) : (
- <p className="text-gray-600 text-sm">
- Already registered?{" "}
- <Link href="/login">
- <a className="text-gray-800 font-semibold">Sign in</a>
- </Link>{" "}
- to your account.
- </p>
- )}
</div>
</div>
);
diff --git a/pages/auth/[domain]/[key].tsx b/pages/auth/[domain]/[key].tsx
new file mode 100644
index 0000000000..14b4068eab
--- /dev/null
+++ b/pages/auth/[domain]/[key].tsx
@@ -0,0 +1,173 @@
+import Head from "next/head";
+import { useRouter } from "next/router";
+import { useState } from "react";
+import BlurImage from "@/components/shared/blur-image";
+import { AlertCircleFill, LoadingDots } from "@/components/shared/icons";
+import { FAVICON_FOLDER } from "@/lib/constants";
+import prisma from "@/lib/prisma";
+
+const title = "Password Required";
+const description =
+ "This link is password protected. Please enter the password to view it.";
+const image = "/static/password-protected.png";
+
+export default function PasswordProtectedLinkPage() {
+ const router = useRouter();
+ const { domain, key } = router.query as { domain: string; key: string };
+ const [validating, setValidating] = useState(false);
+ const [error, setError] = useState(false);
+ const [password, setPassword] = useState("");
+
+ return (
+ <>
+ <Head>
+ <meta property="og:title" content={title} />
+ <meta property="og:description" content={description} />
+ <meta property="og:image" content={image} />
+ <meta name="twitter:card" content="summary_large_image" />
+ <meta name="twitter:title" content={title} />
+ <meta name="twitter:description" content={description} />
+ <meta name="twitter:image" content={image} />
+ <link rel="icon" href={`${FAVICON_FOLDER}/favicon-32x32.png`} />
+ </Head>
+ <main className="w-screen h-screen flex items-center justify-center bg-gray-50">
+ <div className="w-full max-w-md shadow-xl rounded-2xl border border-gray-100 overflow-hidden">
+ <div className="flex flex-col justify-center items-center space-y-3 text-center sm:px-16 px-4 pt-8 py-6 border-b border-gray-200 bg-white">
+ <a href="https://dub.sh" target="_blank" rel="noreferrer">
+ <BlurImage
+ src="/static/logo.png"
+ alt="Dub.sh logo"
+ className="w-10 h-10 rounded-full"
+ width={20}
+ height={20}
+ />
+ </a>
+ <h3 className="font-semibold text-xl">{title}</h3>
+ <p className="text-sm text-gray-500">{description}</p>
+ </div>
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ setValidating(true);
+ fetch(`/api/auth/decrypt-password`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ domain,
+ key,
+ password,
+ }),
+ }).then(async (res) => {
+ if (res.status === 200) {
+ const { url } = await res.json();
+ router.push(url);
+ } else {
+ setValidating(false);
+ setError(true);
+ }
+ });
+ }}
+ className="flex flex-col space-y-4 bg-gray-50 sm:px-16 px-4 py-8"
+ >
+ <div>
+ <label htmlFor="password" className="block text-xs text-gray-600">
+ PASSWORD
+ </label>
+ <div className="relative mt-1 rounded-md shadow-sm">
+ <input
+ type="password"
+ name="password"
+ id="password"
+ required
+ onChange={(e) => {
+ setError(false);
+ setPassword(e.target.value);
+ }}
+ className={`${
+ error
+ ? "border-red-300 text-red-500 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500"
+ } pr-10 block w-full rounded-md focus:outline-none sm:text-sm`}
+ />
+ {error && (
+ <div className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
+ <AlertCircleFill
+ className="h-5 w-5 text-red-500"
+ aria-hidden="true"
+ />
+ </div>
+ )}
+ </div>
+ {error && (
+ <p className="mt-2 text-sm text-red-600" id="slug-error">
+ Incorrect password
+ </p>
+ )}
+ </div>
+
+ <button
+ disabled={validating}
+ className={`${
+ validating
+ ? "cursor-not-allowed bg-gray-100 border-gray-200 text-gray-400"
+ : "bg-black hover:bg-white hover:text-black border-black text-white"
+ } flex justify-center items-center w-full text-sm h-10 rounded-md border transition-all focus:outline-none`}
+ >
+ {validating ? (
+ <LoadingDots color="#808080" />
+ ) : (
+ <p>Authenticate</p>
+ )}
+ </button>
+ </form>
+ </div>
+ </main>
+ </>
+ );
+}
+
+export function getStaticPaths() {
+ return {
+ paths: [],
+ fallback: "blocking",
+ };
+}
+
+export async function getStaticProps(ctx) {
+ const { domain, key } = ctx.params as { domain: string; key: string };
+ const link = await prisma.link.findUnique({
+ where: {
+ domain_key: {
+ domain,
+ key,
+ },
+ },
+ select: {
+ url: true,
+ passwordHash: true,
+ },
+ });
+
+ const { url, passwordHash } = link || {};
+
+ if (!url) {
+ return {
+ notFound: true,
+ revalidate: 1,
+ };
+ } else if (!passwordHash) {
+ return {
+ redirect: {
+ destination: url,
+ },
+ revalidate: 1,
+ };
+ }
+
+ return {
+ props: {},
+ revalidate: 1,
+ };
+}
diff --git a/pages/proxy/[domain]/[key].tsx b/pages/proxy/[domain]/[key].tsx
index 06c7fb480d..c72d496f46 100644
--- a/pages/proxy/[domain]/[key].tsx
+++ b/pages/proxy/[domain]/[key].tsx
@@ -4,8 +4,15 @@ import { escape } from "html-escaper";
import prisma from "@/lib/prisma";
import { LinkProps } from "@/lib/types";
import { redis } from "@/lib/upstash";
+import { getApexDomain } from "@/lib/utils";
-export default function LinkPage({ hostname, title, description, image }) {
+export default function LinkPage({
+ hostname,
+ apexDomain,
+ title,
+ description,
+ image,
+}) {
return (
<>
<Head>
@@ -21,7 +28,7 @@ export default function LinkPage({ hostname, title, description, image }) {
<link
rel="icon"
href={`https://www.google.com/s2/favicons?sz=64&domain_url=${escape(
- hostname,
+ apexDomain,
)}`}
/>
</Head>
@@ -37,7 +44,7 @@ export default function LinkPage({ hostname, title, description, image }) {
<div className="flex space-x-3 bg-gray-100 p-5">
<Image
src={`https://www.google.com/s2/favicons?sz=64&domain_url=${escape(
- hostname,
+ apexDomain,
)}`}
alt={title}
width={300}
@@ -63,11 +70,13 @@ export function getStaticPaths() {
}
export async function getStaticProps(ctx) {
- const { domain, key } = ctx.params;
+ const { domain, key } = ctx.params as { domain: string; key: string };
const link = await prisma.link.findUnique({
where: {
- domain,
- key,
+ domain_key: {
+ domain,
+ key,
+ },
},
});
@@ -88,10 +97,12 @@ export async function getStaticProps(ctx) {
}
const hostname = new URL(url).hostname;
+ const apexDomain = getApexDomain(url);
return {
props: {
hostname,
+ apexDomain,
title,
description,
image,
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index b8c9336bb6..cde62883b4 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -115,18 +115,33 @@ model SentEmail {
model Link {
id String @id @default(cuid())
- domain String
- key String
- url String
- title String?
- description String?
- image String?
- utm_source String?
- utm_medium String?
- utm_campaign String?
- clicks Int @default(0)
+ domain String // domain of the link (e.g. dub.sh) – also stored on Redis
+ key String // key of the link (e.g. /github) – also stored on Redis
+ url String // target url (e.g. https://github.com/steven-tey/dub) – also stored on Redis
+ archived Boolean @default(false) // whether the link is archived or not
+ expiresAt DateTime? // when the link expires – stored on Redis via ttl
+ passwordHash String? // password to access the link – also stored on Redis
+
+ // Custom OG tags – if not set, will use OG tags from target url
+ title String? // OG title for the link (e.g. Dub - Open-Source Bitly Alternative)
+ description String? // OG description for the link (e.g. An open-source link shortener SaaS with built-in analytics and free custom domains.)
+ image String? // OG image for the link (e.g. https://dub.sh/og-image.png)
+
+ // UTM parameters
+ utm_source String? // UTM source for the link (e.g. youtube.com)
+ utm_medium String? // UTM medium for the link (e.g. social)
+ utm_campaign String? // UTM campaign for the link (e.g. summer-sale)
+ utm_term String? // UTM term for the link (e.g. dub)
+ utm_content String? // UTM content for the link (e.g. description)
+
+ clicks Int @default(0) // number of clicks (updated every day via cron + real-time when user views links)
+ clicksUpdatedAt DateTime @default(now()) // last time clicks was updated
+
+ // User who created the link
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String?
+
+ // Project that the link belongs to
project Project? @relation(fields: [domain], references: [domain], onUpdate: Cascade, onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
diff --git a/public/static/password-protected.png b/public/static/password-protected.png
new file mode 100644
index 0000000000..0eba47babb
Binary files /dev/null and b/public/static/password-protected.png differ
diff --git a/yarn.lock b/yarn.lock
index 732e99fb81..1cfc9c9def 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -366,6 +366,21 @@
resolved "https://registry.npmjs.org/@juggle/resize-observer/-/resize-observer-3.4.0.tgz"
integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==
+"@mapbox/node-pre-gyp@^1.0.10":
+ version "1.0.10"
+ resolved "https://registry.yarnpkg.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz#8e6735ccebbb1581e5a7e652244cadc8a844d03c"
+ integrity sha512-4ySo4CjzStuprMwk35H5pPbkymjv1SF3jGLj6rAHp/xT/RF7TL7bd9CTm1xDY49K2qF7jmR/g7k+SkLETP6opA==
+ dependencies:
+ detect-libc "^2.0.0"
+ https-proxy-agent "^5.0.0"
+ make-dir "^3.1.0"
+ node-fetch "^2.6.7"
+ nopt "^5.0.0"
+ npmlog "^5.0.1"
+ rimraf "^3.0.2"
+ semver "^7.3.5"
+ tar "^6.1.11"
+
"@motionone/animation@^10.13.1":
version "10.14.0"
resolved "https://registry.npmjs.org/@motionone/animation/-/animation-10.14.0.tgz"
@@ -1694,6 +1709,14 @@ archy@~1.0.0:
resolved "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz"
integrity sha512-Xg+9RwCg/0p32teKdGMPTPnVXKD0w3DfHnFTficozsAgsvq2XenPJq/MYpzzQ/v8zrOyJn6Ds39VA4JIDwFfqw==
+are-we-there-yet@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz#372e0e7bd279d8e94c653aaa1f67200884bf3e1c"
+ integrity sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==
+ dependencies:
+ delegates "^1.0.0"
+ readable-stream "^3.6.0"
+
are-we-there-yet@^3.0.0:
version "3.0.1"
resolved "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-3.0.1.tgz"
@@ -1774,6 +1797,14 @@ balanced-match@^1.0.0:
resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
+bcrypt@^5.1.0:
+ version "5.1.0"
+ resolved "https://registry.yarnpkg.com/bcrypt/-/bcrypt-5.1.0.tgz#bbb27665dbc400480a524d8991ac7434e8529e17"
+ integrity sha512-RHBS7HI5N5tEnGTmtR/pppX0mmDSBpQ4aCBsj7CEQfYXDcO74A8sIBYcJMuCsis2E81zDxeENYhv66oZwLiA+Q==
+ dependencies:
+ "@mapbox/node-pre-gyp" "^1.0.10"
+ node-addon-api "^5.0.0"
+
big-integer@^1.6.17:
version "1.6.51"
resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.51.tgz#0df92a5d9880560d3ff2d5fd20245c889d130686"
@@ -2163,7 +2194,7 @@ color-string@^1.6.0:
color-name "^1.0.0"
simple-swizzle "^0.2.2"
-color-support@^1.1.3:
+color-support@^1.1.2, color-support@^1.1.3:
version "1.1.3"
resolved "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz"
integrity sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==
@@ -2224,7 +2255,7 @@ config-chain@^1.1.13:
ini "^1.3.4"
proto-list "~1.2.1"
-console-control-strings@^1.1.0:
+console-control-strings@^1.0.0, console-control-strings@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz"
integrity sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==
@@ -2469,6 +2500,11 @@ depd@^1.1.2:
resolved "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz"
integrity sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==
+detect-libc@^2.0.0:
+ version "2.0.1"
+ resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-2.0.1.tgz#e1897aa88fa6ad197862937fbc0441ef352ee0cd"
+ integrity sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==
+
version "2.0.4"
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.0.4.tgz#014ee8f8f669c5c58023da64b8179c083a28c46c"
@@ -2998,6 +3034,21 @@ function-bind@^1.1.1:
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==
+gauge@^3.0.0:
+ version "3.0.2"
+ resolved "https://registry.yarnpkg.com/gauge/-/gauge-3.0.2.tgz#03bf4441c044383908bcfa0656ad91803259b395"
+ integrity sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==
+ dependencies:
+ aproba "^1.0.3 || ^2.0.0"
+ color-support "^1.1.2"
+ console-control-strings "^1.0.0"
+ has-unicode "^2.0.1"
+ object-assign "^4.1.1"
+ signal-exit "^3.0.0"
+ string-width "^4.2.3"
+ strip-ansi "^6.0.1"
+ wide-align "^1.1.2"
+
gauge@^4.0.3:
version "4.0.4"
resolved "https://registry.npmjs.org/gauge/-/gauge-4.0.4.tgz"
@@ -3832,6 +3883,13 @@ mailing@^0.8.3-next.0:
uglify-js "^3.15.4"
yargs "^17.5.1"
+make-dir@^3.1.0:
+ version "3.1.0"
+ resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
+ integrity sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==
+ dependencies:
+ semver "^6.0.0"
+
make-fetch-happen@^10.0.3, make-fetch-happen@^10.0.6, make-fetch-happen@^10.2.0:
version "10.2.1"
resolved "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.2.1.tgz"
@@ -4434,6 +4492,11 @@ no-case@^3.0.4:
lower-case "^2.0.2"
tslib "^2.0.3"
+node-addon-api@^5.0.0:
+ version "5.0.0"
+ resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-5.0.0.tgz#7d7e6f9ef89043befdb20c1989c905ebde18c501"
+ integrity sha512-CvkDw2OEnme7ybCykJpVcKH+uAOLV2qLqiyla128dN9TkEWfrYmxG6C2boDe5KcNQqZF3orkqzGgOMvZ/JNekA==
+
node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.7:
version "2.6.7"
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz"
@@ -4677,6 +4740,16 @@ npm@^8.19.0:
which "^2.0.2"
write-file-atomic "^4.0.1"
+npmlog@^5.0.1:
+ version "5.0.1"
+ resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-5.0.1.tgz#f06678e80e29419ad67ab964e0fa69959c1eb8b0"
+ integrity sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==
+ dependencies:
+ are-we-there-yet "^2.0.0"
+ console-control-strings "^1.1.0"
+ gauge "^3.0.0"
+ set-blocking "^2.0.0"
+
npmlog@^6.0.0, npmlog@^6.0.2:
version "6.0.2"
resolved "https://registry.npmjs.org/npmlog/-/npmlog-6.0.2.tgz"
@@ -5472,7 +5545,7 @@ semver@^5.6.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
-semver@^6.3.0:
+semver@^6.0.0, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
@@ -5513,7 +5586,7 @@ sigmund@^1.0.1:
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
integrity sha512-fCvEXfh6NWpm+YSuY2bpXb/VIihqWA6hLsgboC+0nl71Q7N7o2eaCW8mJa/NLvQhs6jpd3VZV4UiUQlV6+lc8g==
-signal-exit@^3.0.7:
+signal-exit@^3.0.0, signal-exit@^3.0.7:
version "3.0.7"
resolved "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz"
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==
@@ -6088,7 +6161,7 @@ which@^2.0.2:
dependencies:
isexe "^2.0.0"
-wide-align@^1.1.5:
+wide-align@^1.1.2, wide-align@^1.1.5:
version "1.1.5"
resolved "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz"
integrity sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==