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.

remove barrel import, handle email domain

Steven Tey303f3f8b6774
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx
index 21a7ac90ff..bfcd7c1768 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx
@@ -9,6 +9,7 @@ import UserInfo, { UserInfoProps } from "./user-info";
export function ImpersonateUser() {
const [data, setData] = useState<UserInfoProps | null>(null);
+ const [blockEmailDomain, setBlockEmailDomain] = useState(false);
return (
<div className="flex flex-col space-y-5">
@@ -21,6 +22,7 @@ export function ImpersonateUser() {
}),
}).then(async (res) => {
if (res.ok) {
+ setBlockEmailDomain(false);
setData(await res.json());
} else {
const error = await res.text();
@@ -34,9 +36,14 @@ export function ImpersonateUser() {
{data && (
<form
action={async () => {
+ const emailDomain = data.email.split("@")[1];
+ const blockDomainMessage = blockEmailDomain
+ ? ` and block signups from @${emailDomain}`
+ : "";
+
if (
!confirm(
- `This will ban the user ${data.email} and delete all their workspaces and links. Are you sure?`,
+ `This will ban the user ${data.email} and delete all their workspaces and links${blockDomainMessage}. Are you sure?`,
)
) {
return;
@@ -45,6 +52,7 @@ export function ImpersonateUser() {
method: "POST",
body: JSON.stringify({
email: data.email,
+ blockEmailDomain,
}),
}).then(async (res) => {
if (res.ok) {
@@ -57,6 +65,15 @@ export function ImpersonateUser() {
}}
>
<UserInfo data={data} />
+ <label className="mt-4 flex cursor-pointer items-center gap-2 text-sm text-neutral-600">
+ <input
+ type="checkbox"
+ checked={blockEmailDomain}
+ onChange={(e) => setBlockEmailDomain(e.target.checked)}
+ className="rounded border-neutral-300 text-neutral-900 focus:ring-neutral-500"
+ />
+ Also block signups from @{data.email.split("@")[1]}
+ </label>
<div className="mt-4">
<BanButton />
</div>
diff --git a/apps/web/app/(ee)/api/admin/ban/route.ts b/apps/web/app/(ee)/api/admin/ban/route.ts
index 9d27bcff47..a8c325233c 100644
--- a/apps/web/app/(ee)/api/admin/ban/route.ts
+++ b/apps/web/app/(ee)/api/admin/ban/route.ts
@@ -1,6 +1,7 @@
import { deleteWorkspaceAdmin } from "@/lib/api/workspaces/delete-workspace";
import { withAdmin } from "@/lib/auth";
import { updateConfig } from "@/lib/edge-config";
+import { extractEmailDomain } from "@/lib/email/extract-email-domain";
import { prisma } from "@/lib/prisma";
import { isStored, storage } from "@/lib/storage";
import { R2_URL } from "@dub/utils";
@@ -10,7 +11,7 @@ import { NextResponse } from "next/server";
// POST /api/admin/ban
export const POST = withAdmin(
async ({ req }) => {
- const { email } = await req.json();
+ const { email, blockEmailDomain } = await req.json();
const user = await prisma.user.findUniqueOrThrow({
where: {
@@ -38,6 +39,8 @@ export const POST = withAdmin(
},
});
+ const emailDomain = extractEmailDomain(email);
+
console.log(
`Found user ${user.email} with ${user.projects.length} workspaces`,
);
@@ -54,6 +57,12 @@ export const POST = withAdmin(
key: "emails",
value: email,
}),
+ blockEmailDomain &&
+ emailDomain &&
+ updateConfig({
+ key: "emailDomainTerms",
+ value: emailDomain,
+ }),
]);
// delete user
diff --git a/apps/web/app/api/links/exists/route.ts b/apps/web/app/api/links/exists/route.ts
index d6af1349dc..16e4e2bedd 100644
--- a/apps/web/app/api/links/exists/route.ts
+++ b/apps/web/app/api/links/exists/route.ts
@@ -2,11 +2,9 @@ import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";
import { keyChecks, processKey } from "@/lib/api/links/utils";
import { getWorkspaceViaEdge } from "@/lib/planetscale";
import { domainKeySchema } from "@/lib/zod/schemas/links";
-import { workspaceIdSchema } from "@/lib/zod/schemas/workspaces";
import { getSearchParams } from "@dub/utils";
import { NextRequest, NextResponse } from "next/server";
-
-export const runtime = "edge";
+import * as z from "zod/v4";
// GET /api/links/exists – run keyChecks on the key
export const GET = async (req: NextRequest) => {
@@ -14,7 +12,14 @@ export const GET = async (req: NextRequest) => {
const searchParams = getSearchParams(req.url);
let { domain, key, workspaceId } = domainKeySchema
- .and(workspaceIdSchema)
+ .and(
+ z.object({
+ workspaceId: z
+ .string()
+ .min(1, "Workspace ID is required.")
+ .describe("The ID of the workspace the link belongs to."),
+ }),
+ )
.parse(searchParams);
const processedKey = processKey({ domain, key });
diff --git a/apps/web/lib/edge-config/update.ts b/apps/web/lib/edge-config/update.ts
index 2bb6cb62aa..11eac37f09 100644
--- a/apps/web/lib/edge-config/update.ts
+++ b/apps/web/lib/edge-config/update.ts
@@ -12,6 +12,7 @@ export const updateConfig = async ({
| "keys"
| "whitelist"
| "emails"
+ | "emailDomainTerms"
| "reserved"
| "reservedUsernames"
| "partnersPortal";
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index bd03808b98..f71e14f1c9 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -12,13 +12,6 @@ export {
trackedSitemapSchema,
} from "./site-visit-tracking";
-export const workspaceIdSchema = z.object({
- workspaceId: z
- .string()
- .min(1, "Workspace ID is required.")
- .describe("The ID of the workspace the link belongs to."),
-});
-
export const WorkspaceSchema = z
.object({
id: z.string().describe("The unique ID of the workspace."),