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 domain verify issue

Steven Teya5a21d4f0016
diff --git a/apps/web/lib/api/domains.ts b/apps/web/lib/api/domains.ts
index 3e007f07c4..841d9d40a5 100644
--- a/apps/web/lib/api/domains.ts
+++ b/apps/web/lib/api/domains.ts
@@ -64,9 +64,9 @@ export const addDomainToVercel = async (
"Content-Type": "application/json",
},
body: JSON.stringify({
- name: domain,
+ name: domain.toLowerCase(),
...(redirectToApex && {
- redirect: getDomainWithoutWWW(domain),
+ redirect: getDomainWithoutWWW(domain.toLowerCase()),
}),
}),
},
@@ -93,7 +93,7 @@ export const removeDomainFromVercel = async (domain: string) => {
// the apex domain is being used by other domains on Dub
// so we should only remove it from our Vercel project
return await fetch(
- `https://api.vercel.com/v9/projects/${process.env.PROJECT_ID_VERCEL}/domains/${domain}?teamId=${process.env.TEAM_ID_VERCEL}`,
+ `https://api.vercel.com/v9/projects/${process.env.PROJECT_ID_VERCEL}/domains/${domain.toLowerCase()}?teamId=${process.env.TEAM_ID_VERCEL}`,
{
headers: {
Authorization: `Bearer ${process.env.AUTH_BEARER_TOKEN}`,
@@ -105,7 +105,7 @@ export const removeDomainFromVercel = async (domain: string) => {
// this is the only domain using this apex domain
// so we can remove it entirely from our Vercel team
return await fetch(
- `https://api.vercel.com/v6/domains/${domain}?teamId=${process.env.TEAM_ID_VERCEL}`,
+ `https://api.vercel.com/v6/domains/${domain.toLowerCase()}?teamId=${process.env.TEAM_ID_VERCEL}`,
{
headers: {
Authorization: `Bearer ${process.env.AUTH_BEARER_TOKEN}`,
@@ -118,7 +118,7 @@ export const removeDomainFromVercel = async (domain: string) => {
export const getDomainResponse = async (domain: string) => {
return await fetch(
- `https://api.vercel.com/v9/projects/${process.env.PROJECT_ID_VERCEL}/domains/${domain}?teamId=${process.env.TEAM_ID_VERCEL}`,
+ `https://api.vercel.com/v9/projects/${process.env.PROJECT_ID_VERCEL}/domains/${domain.toLowerCase()}?teamId=${process.env.TEAM_ID_VERCEL}`,
{
method: "GET",
headers: {
@@ -133,7 +133,7 @@ export const getDomainResponse = async (domain: string) => {
export const getConfigResponse = async (domain: string) => {
return await fetch(
- `https://api.vercel.com/v6/domains/${domain}/config?teamId=${process.env.TEAM_ID_VERCEL}`,
+ `https://api.vercel.com/v6/domains/${domain.toLowerCase()}/config?teamId=${process.env.TEAM_ID_VERCEL}`,
{
method: "GET",
headers: {
@@ -146,7 +146,7 @@ export const getConfigResponse = async (domain: string) => {
export const verifyDomain = async (domain: string) => {
return await fetch(
- `https://api.vercel.com/v9/projects/${process.env.PROJECT_ID_VERCEL}/domains/${domain}/verify?teamId=${process.env.TEAM_ID_VERCEL}`,
+ `https://api.vercel.com/v9/projects/${process.env.PROJECT_ID_VERCEL}/domains/${domain.toLowerCase()}/verify?teamId=${process.env.TEAM_ID_VERCEL}`,
{
method: "POST",
headers: {
diff --git a/apps/web/ui/domains/domain-card.tsx b/apps/web/ui/domains/domain-card.tsx
index 7e711a448d..e3f250cc0a 100644
--- a/apps/web/ui/domains/domain-card.tsx
+++ b/apps/web/ui/domains/domain-card.tsx
@@ -7,7 +7,13 @@ import {
ExternalLink,
XCircleFill,
} from "@/ui/shared/icons";
-import { Button, LoadingCircle, LoadingDots, NumberTooltip } from "@dub/ui";
+import {
+ Button,
+ LoadingCircle,
+ LoadingDots,
+ NumberTooltip,
+ useIntersectionObserver,
+} from "@dub/ui";
import { capitalize, fetcher, nFormatter, truncate } from "@dub/utils";
import { QrCode } from "lucide-react";
import Link from "next/link";
@@ -16,6 +22,7 @@ import useSWR, { mutate } from "swr";
import { useAddEditDomainModal } from "../modals/add-edit-domain-modal";
import { useLinkQRModal } from "../modals/link-qr-modal";
import DomainConfiguration from "./domain-configuration";
+import { useRef } from "react";
export default function DomainCard({ props }: { props: DomainProps }) {
const { id, slug } = useWorkspace();
@@ -29,17 +36,26 @@ export default function DomainCard({ props }: { props: DomainProps }) {
},
});
+ const domainRef = useRef<any>();
+ const entry = useIntersectionObserver(domainRef, {});
+ const isVisible = !!entry?.isIntersecting;
+
const { data, isValidating } = useSWR<{
status: DomainVerificationStatusProps;
response: any;
}>(
id &&
+ isVisible &&
!showLinkQRModal && // Don't fetch if QR modal is open – it'll cause it to re-render
`/api/domains/${domain}/verify?workspaceId=${id}`,
fetcher,
{
+ revalidateOnFocus: true,
revalidateOnMount: true,
- refreshInterval: verified ? 0 : 5000, // Don't need to constantly refresh if domain is verified
+ revalidateOnReconnect: true,
+ refreshWhenOffline: false,
+ refreshWhenHidden: false,
+ refreshInterval: 0,
},
);
@@ -61,7 +77,10 @@ export default function DomainCard({ props }: { props: DomainProps }) {
<>
<AddEditDomainModal />
<LinkQRModal />
- <div className="flex flex-col space-y-3 rounded-lg border border-gray-200 bg-white px-5 py-8 sm:px-10">
+ <div
+ ref={domainRef}
+ className="flex flex-col space-y-3 rounded-lg border border-gray-200 bg-white px-5 py-8 sm:px-10"
+ >
<div className="flex flex-col justify-between space-y-4 sm:flex-row sm:space-x-4">
<div className="flex items-center space-x-2">
<a