The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
added more steps + fix modularity
Steven Teyb0fd3a654c8c
diff --git a/apps/docs/images/planetscale-add-credentials.png b/apps/docs/images/planetscale-add-credentials.pngnew file mode 100644index 0000000000..e9ce114359Binary files /dev/null and b/apps/docs/images/planetscale-add-credentials.png differdiff --git a/apps/docs/images/planetscale-choose-framework.png b/apps/docs/images/planetscale-choose-framework.pngnew file mode 100644index 0000000000..67d4577817Binary files /dev/null and b/apps/docs/images/planetscale-choose-framework.png differdiff --git a/apps/docs/images/resend-api-key.png b/apps/docs/images/resend-api-key.pngnew file mode 100644index 0000000000..3a45bbdeecBinary files /dev/null and b/apps/docs/images/resend-api-key.png differdiff --git a/apps/docs/images/upstash-qstash-tokens.png b/apps/docs/images/upstash-qstash-tokens.pngnew file mode 100644index 0000000000..f865a356bdBinary files /dev/null and b/apps/docs/images/upstash-qstash-tokens.png differdiff --git a/apps/docs/images/upstash-copy-token.png b/apps/docs/images/upstash-redis-tokens.pngsimilarity index 100%rename from apps/docs/images/upstash-copy-token.pngrename to apps/docs/images/upstash-redis-tokens.pngdiff --git a/apps/docs/self-hosting/guide.mdx b/apps/docs/self-hosting/guide.mdxindex 627330119b..143f218d75 100644--- a/apps/docs/self-hosting/guide.mdx+++ b/apps/docs/self-hosting/guide.mdx@@ -12,9 +12,10 @@ Before you begin, make sure you have the following:- A [Tinybird](https://www.tinybird.co/) account- An [Upstash](https://upstash.com/) account- A [Planetscale](https://planetscale.com/) account+- A [Resend](https://resend.com/) account- A [Vercel](https://vercel.com/) account-## Step 1: Clone the repository+## Step 1: Local setupFirst, clone the [Dub repo](https://dub.sh/github) into a public GitHub repository. If you are planning to distribute the code, make sure to keep the source code public to comply with our [AGPLv3 license](https://dub.sh/license).@@ -22,12 +23,35 @@ First, clone the [Dub repo](https://dub.sh/github) into a public GitHub repositogit clone https://github.com/steven-tey/dub.git```-## Step 2. Publish Tinybird endpoints+Run the following command to install the dependencies:++```bash+pnpm i+```++Delete the `apps/docs` directory since it's not needed for self-hosting:++```bash+rm -rf apps/docs+```++Convert the `.env.example` file to `.env`. You can start filling in the first few environment variables:++```bash+# The domain that your app will be hosted on+NEXT_PUBLIC_APP_DOMAIN=+# The short domain that your app will be using (could be the same as the above)+NEXT_PUBLIC_APP_SHORT_DOMAIN=+```++You will fill in the remaining environment variables in the following steps.++## Step 2: Publish Tinybird endpointsNext, you'll need to publish the Tinybird endpoints:1. In your [Tinybrd](https://tinybird.co/) account, create a new Workspace.-2. Copy your `admin` [Auth Token](https://www.tinybird.co/docs/concepts/auth-tokens.html). You'll need this in step 5, and also for the `TINYBIRD_API_KEY` environment variable in later steps.+2. Copy your `admin` [Auth Token](https://www.tinybird.co/docs/concepts/auth-tokens.html). Paste this token as the `TINYBIRD_API_KEY` environment variable in your `.env` file.3. In your cloned Dub repo, navigate to the `packages/tinybird` directory.4. Install the Tinybird CLI with `pip install tinybird-cli` (requires Python >= 3.8).5. Run `tb auth` and paste your `admin` Auth Token.@@ -51,15 +75,59 @@ $ tb push...```-## Step 3. Set up Upstash Redis database+## Step 3: Set up Upstash Redis databaseNext, you'll need to set up the Upstash Redis database:-1. In your [Upstash](https://upstash.com/) account, create a new database.+1. In your [Upstash account](https://console.upstash.com/), create a new database.2. For better performance & read times, we recommend setting up a global database with several read regions.-3. Once your database is created, copy the `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from the **REST API** section. You'll need these tokens in later steps.+3. Once your database is created, copy the `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from the **REST API** section into your `.env` file.++++4. Navigate to the [QStash tab](https://console.upstash.com/qstash) and copy the `QSTASH_URL`, `QSTASH_CURRENT_SIGNING_KEY`, and `QSTASH_NEXT_SIGNING_KEY` from the **Request Builder** section into your `.env` file.++++## Step 4: Set up Planetscale database++In your [Planetscale account](https://app.planetscale.com/), create a new database. You can use the free tier for this project.++Once your database is created, you'll be prompted to select your language or Framework. Select **Prisma**.++++Then, you'll have to create a new password for your database. Once the password is created, scroll down to the **Add credentials to .env** section and copy the `DATABASE_URL` into your `.env` file.++++Going back to your terminal, navigate to the `apps/web` directory and run the following command to generate the Prisma client:++```bash+npx prisma generate+```++Then, create the database tables with the following command:++```bash+npx prisma db push+```++## Step 5: Set up Resend++Next, you'll need to set up Resend for transactional emails (e.g. magic link emails):++1. In your [Resend account](https://resend.com/overview), create a new API key.++++2. Copy the API key into your `.env` file as the `RESEND_API_KEY` environment variable.++## Step 6: Deploy to Vercel++Once you've set up all the databases, you can deploy your app to Vercel:-+1. In your [Vercel account](https://vercel.com/), create a new project.diff --git a/apps/web/.env.example b/apps/web/.env.exampleindex 3dc3351d96..de20248141 100644--- a/apps/web/.env.example+++ b/apps/web/.env.example@@ -26,35 +26,18 @@ QSTASH_TOKEN=QSTASH_CURRENT_SIGNING_KEY=QSTASH_NEXT_SIGNING_KEY=-# Generate a random secret here: https://generate-secret.vercel.app/32-NEXTAUTH_SECRET=-NEXTAUTH_URL=http://localhost:8888 # (only needed for localhost)-# MySQL Database via Planetscale# Get your MySQL Database URL here: https://planetscale.com/docs/tutorials/connect-nodejs-appDATABASE_URL=-# Resend – required for emails+# Generate a random secret here: https://generate-secret.vercel.app/32+NEXTAUTH_SECRET=+NEXTAUTH_URL=http://localhost:8888 # (only needed for localhost)++# Required for email login# Get your Resend API Key here: https://resend.com/docs/send-with-nextjsRESEND_API_KEY=-# Required for image uploads-# Get your Cloudinary URL here: https://cloudinary.com/documentation/node_integration#configuration-CLOUDINARY_URL=--# Required for Google Auth-# Learn how to set this up here: https://next-auth.js.org/providers/google-GOOGLE_CLIENT_ID=-GOOGLE_CLIENT_SECRET=--# Required for Custom Social Media Cards feature-# Apply for an API key here: https://unsplash.com/developers-UNSPLASH_ACCESS_KEY=--# Required for local testing-# Get your ngrok URL here: https://ngrok.com/-NGROK_URL=-##################################### OPTIONAL ENV VARS #####################################@@ -65,6 +48,11 @@ NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=STRIPE_SECRET_KEY=STRIPE_WEBHOOK_SECRET=+# Used for Google Login+# Learn how to set this up here: https://next-auth.js.org/providers/google+GOOGLE_CLIENT_ID=+GOOGLE_CLIENT_SECRET=+# Edge Config – used for admin features like banning users, rate limiting etc.# Create one here: https://vercel.com/docs/storage/edge-config# Alternatively, if you don't need this, you can also remove `lib/edge-config.ts`@@ -78,17 +66,29 @@ NEXT_PUBLIC_BITLY_CLIENT_ID=BITLY_CLIENT_SECRET=NEXT_PUBLIC_BITLY_REDIRECT_URI=http://localhost:8888/api/callback/bitly+# Used for Custom Social Media Cards feature+# Apply for an API key here: https://unsplash.com/developers+UNSPLASH_ACCESS_KEY=++# Used for image uploads+# Get your Cloudinary URL here: https://cloudinary.com/documentation/node_integration#configuration+CLOUDINARY_URL=+# Used for internal monitoring & paging# You can remove this by removing `DUB_SLACK_HOOK_CRON` and `DUB_SLACK_HOOK_LINKS` from the codebaseDUB_SLACK_HOOK_CRON=DUB_SLACK_HOOK_LINKS=+# Used for local testing+# Get your ngrok URL here: https://ngrok.com/+NGROK_URL=+############################################ DUB.CO INTERNAL USE ONLY ############################################# For the official Dub.co app-NEXT_PUBLIC_IS_DUB=true+NEXT_PUBLIC_IS_DUB=# For cron jobsCRON_SECRET=diff --git a/apps/web/app/api/auth/account-exists/route.ts b/apps/web/app/api/auth/account-exists/route.tsindex 367e29e905..9dee4df11f 100644--- a/apps/web/app/api/auth/account-exists/route.ts+++ b/apps/web/app/api/auth/account-exists/route.ts@@ -22,6 +22,10 @@ export async function POST(req: NextRequest) {});}+ if (!process.env.NEXT_PUBLIC_IS_DUB) {+ return NextResponse.json({ exists: true });+ }+const user = await conn.execute("SELECT email FROM User WHERE email = ?", [email]).then((res) => res.rows[0]);diff --git a/apps/web/app/app.dub.co/(auth)/login/page.tsx b/apps/web/app/app.dub.co/(auth)/login/page.tsxindex a2790880d3..ba6a36af01 100644--- a/apps/web/app/app.dub.co/(auth)/login/page.tsx+++ b/apps/web/app/app.dub.co/(auth)/login/page.tsx@@ -10,13 +10,6 @@ export const metadata = constructMetadata({export default function LoginPage() {return (<div className="relative z-10 mt-[calc(30vh)] h-fit w-full max-w-md overflow-hidden border border-gray-100 sm:rounded-2xl sm:shadow-xl">- <a- href={`${HOME_DOMAIN}/blog/rebrand`}- target="_blank"- className="absolute right-3 top-3 rounded-full border border-gray-300 px-4 py-1 text-xs font-medium shadow-[inset_10px_-50px_94px_0_rgb(199,199,199,0.1)] backdrop-blur transition-all hover:border-gray-500 hover:bg-white/50"- >- We've rebranded!- </a><div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 bg-white px-4 py-6 pt-8 text-center sm:px-16"><a href={HOME_DOMAIN}><Logo className="h-10 w-10" />diff --git a/apps/web/app/app.dub.co/(auth)/register/page.tsx b/apps/web/app/app.dub.co/(auth)/register/page.tsxindex e5df9b05d7..df644c321b 100644--- a/apps/web/app/app.dub.co/(auth)/register/page.tsx+++ b/apps/web/app/app.dub.co/(auth)/register/page.tsx@@ -10,13 +10,6 @@ export const metadata = constructMetadata({export default function RegisterPage() {return (<div className="relative z-10 mt-[calc(30vh)] h-fit w-full max-w-md overflow-hidden border border-gray-100 sm:rounded-2xl sm:shadow-xl">- <a- href={`${HOME_DOMAIN}/blog/rebrand`}- target="_blank"- className="absolute right-3 top-3 rounded-full border border-gray-300 px-4 py-1 text-xs font-medium shadow-[inset_10px_-50px_94px_0_rgb(199,199,199,0.1)] backdrop-blur transition-all hover:border-gray-500 hover:bg-white/50"- >- We've rebranded!- </a><div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 bg-white px-4 py-6 pt-8 text-center sm:px-16"><a href={HOME_DOMAIN}><Logo className="h-10 w-10" />diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.tsindex 154efba84c..3983433e64 100644--- a/apps/web/lib/auth/options.ts+++ b/apps/web/lib/auth/options.ts@@ -296,7 +296,8 @@ export const authOptions: NextAuthOptions = {// (this is a workaround because the `isNewUser` flag is triggered when a user does `dangerousEmailAccountLinking`)if (user?.createdAt &&- new Date(user.createdAt).getTime() > Date.now() - 10000+ new Date(user.createdAt).getTime() > Date.now() - 10000 &&+ process.env.NEXT_PUBLIC_IS_DUB) {await Promise.allSettled([fetch(diff --git a/apps/web/lib/edge-config.ts b/apps/web/lib/edge-config.tsindex 9c9c836808..5b08f65dce 100644--- a/apps/web/lib/edge-config.ts+++ b/apps/web/lib/edge-config.ts@@ -51,6 +51,9 @@ export const isWhitelistedEmail = async (email: string) => {};export const isBlacklistedEmail = async (email: string) => {+ if (!process.env.NEXT_PUBLIC_IS_DUB) {+ return false;+ }let blacklistedEmails;try {blacklistedEmails = await get("emails");diff --git a/packages/utils/src/constants/index.ts b/packages/utils/src/constants/index.tsindex 3c9fa00138..3dc22a5b84 100644--- a/packages/utils/src/constants/index.ts+++ b/packages/utils/src/constants/index.ts@@ -54,7 +54,7 @@ export const APP_DOMAIN_WITH_NGROK =? `https://app.${process.env.NEXT_PUBLIC_APP_DOMAIN}`: process.env.NEXT_PUBLIC_VERCEL_ENV === "preview"? `https://preview.${process.env.NEXT_PUBLIC_APP_DOMAIN}`- : process.env.NGROK_URL;+ : process.env.NGROK_URL || "http://localhost:8888";export const API_HOSTNAMES = new Set([`api.${process.env.NEXT_PUBLIC_APP_DOMAIN}`,