Skip to content

Commit b026b28

Browse files
committed
improve admin
1 parent c524f77 commit b026b28

File tree

3 files changed

+65
-40
lines changed

3 files changed

+65
-40
lines changed

apps/web/app/admin.dub.co/(dashboard)/components/user-info.tsx

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,25 @@ export interface UserInfoProps {
1515
domains: number;
1616
links: number;
1717
}[];
18-
impersonateUrl: string;
18+
impersonateUrl: {
19+
app: string;
20+
partners: string;
21+
};
1922
}
2023

2124
export default function UserInfo({ data }: { data: UserInfoProps }) {
22-
const [copied, copyToClipboard] = useCopyToClipboard();
23-
2425
return (
25-
<>
26-
<div className="flex w-full items-center space-x-3">
27-
<input
28-
type="email"
29-
name="email"
30-
id="email"
31-
value={data.email}
32-
readOnly
33-
className="w-full rounded-md border-gray-300 text-sm text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500"
34-
/>
35-
<button
36-
type="button"
37-
onClick={() =>
38-
toast.promise(copyToClipboard(data.impersonateUrl), {
39-
success: "Copied to clipboard",
40-
})
41-
}
42-
className="rounded-md border border-gray-300 p-2"
43-
>
44-
{copied ? (
45-
<Tick className="h-5 w-5 text-gray-500" />
46-
) : (
47-
<Copy className="h-5 w-5 text-gray-500" />
48-
)}
49-
</button>
50-
</div>
26+
<div className="grid gap-2">
27+
<LoginLinkCopyButton
28+
text="app.dub.co login link"
29+
url={data.impersonateUrl.app}
30+
/>
31+
<LoginLinkCopyButton
32+
text="partners.dub.co login link"
33+
url={data.impersonateUrl.partners}
34+
/>
5135
{Object.keys(data.defaultDomainLinks).length > 0 && (
52-
<div className="mt-2 grid divide-y divide-gray-200">
36+
<div className="grid divide-y divide-gray-200">
5337
{Object.entries(data.defaultDomainLinks).map(([domain, count]) => (
5438
<div key={domain} className="flex justify-between py-2">
5539
<div className="flex items-center space-x-2">
@@ -61,7 +45,7 @@ export default function UserInfo({ data }: { data: UserInfoProps }) {
6145
))}
6246
</div>
6347
)}
64-
<div className="mt-2 grid grid-cols-2 gap-4">
48+
<div className="grid grid-cols-2 gap-4">
6549
{data.workspaces.map((workspace) => (
6650
<div
6751
key={workspace.slug}
@@ -100,6 +84,33 @@ export default function UserInfo({ data }: { data: UserInfoProps }) {
10084
</div>
10185
))}
10286
</div>
103-
</>
87+
</div>
10488
);
10589
}
90+
91+
const LoginLinkCopyButton = ({ text, url }: { text: string; url: string }) => {
92+
const [copied, copyToClipboard] = useCopyToClipboard();
93+
94+
return (
95+
<div className="flex w-full items-center space-x-3">
96+
<div className="w-full rounded-md border border-gray-300 px-4 py-2 text-sm text-gray-900">
97+
{text}
98+
</div>
99+
<button
100+
type="button"
101+
onClick={() =>
102+
toast.promise(copyToClipboard(url), {
103+
success: "Copied to clipboard",
104+
})
105+
}
106+
className="rounded-md border border-gray-300 p-2"
107+
>
108+
{copied ? (
109+
<Tick className="h-5 w-5 text-gray-500" />
110+
) : (
111+
<Copy className="h-5 w-5 text-gray-500" />
112+
)}
113+
</button>
114+
</div>
115+
);
116+
};

apps/web/app/api/admin/impersonate/route.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { hashToken, withAdmin } from "@/lib/auth";
22
import { prisma } from "@/lib/prisma";
3-
import { DUB_DOMAINS_ARRAY } from "@dub/utils";
3+
import { APP_DOMAIN, DUB_DOMAINS_ARRAY, PARTNERS_DOMAIN } from "@dub/utils";
44
import { randomBytes } from "crypto";
55
import { NextResponse } from "next/server";
66

@@ -97,11 +97,18 @@ async function getImpersonateUrl(email: string) {
9797
},
9898
});
9999

100-
const params = new URLSearchParams({
101-
callbackUrl: process.env.NEXTAUTH_URL as string,
102-
email,
103-
token,
104-
});
105-
106-
return `${process.env.NEXTAUTH_URL}/api/auth/callback/email?${params}`;
100+
return {
101+
app: `${APP_DOMAIN}/api/auth/callback/email?${new URLSearchParams({
102+
callbackUrl: APP_DOMAIN,
103+
email,
104+
token,
105+
})}`,
106+
partners: `${PARTNERS_DOMAIN}/api/auth/callback/email?${new URLSearchParams(
107+
{
108+
callbackUrl: PARTNERS_DOMAIN,
109+
email,
110+
token,
111+
},
112+
)}`,
113+
};
107114
}

packages/utils/src/constants/main.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export const ADMIN_HOSTNAMES = new Set([
4545
"admin.localhost:8888",
4646
]);
4747

48+
export const PARTNERS_DOMAIN =
49+
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
50+
? `https://partners.${process.env.NEXT_PUBLIC_APP_DOMAIN}`
51+
: process.env.NEXT_PUBLIC_VERCEL_ENV === "preview"
52+
? `https://partners-staging.${process.env.NEXT_PUBLIC_APP_DOMAIN}`
53+
: "http://partners.localhost:8888";
54+
4855
export const PARTNERS_HOSTNAMES = new Set([
4956
`partners.${process.env.NEXT_PUBLIC_APP_DOMAIN}`,
5057
`partners-staging.${process.env.NEXT_PUBLIC_APP_DOMAIN}`,

0 commit comments

Comments
 (0)