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.

address coderabbit feedback

Steven Teyb71914ac0242
diff --git a/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page-client.tsx
index 54b428d0ef..dea26d9684 100644
--- a/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page-client.tsx
@@ -3,16 +3,14 @@
import { TokenProps } from "@/lib/types";
import { useDeleteTokenModal } from "@/ui/modals/delete-token-modal";
import {
- Alert,
- AlertDescription,
- AlertTitle,
IconMenu,
LoadingSpinner,
Popover,
TokenAvatar,
+ TriangleWarning,
} from "@dub/ui";
import { fetcher, timeAgo } from "@dub/utils";
-import { FolderOpen, Info, MoreVertical, Trash } from "lucide-react";
+import { FolderOpen, MoreVertical, Trash } from "lucide-react";
import { useState } from "react";
import useSWR from "swr";
@@ -24,17 +22,15 @@ export default function TokensPageClient() {
return (
<>
- <Alert>
- <Info className="mt-2 h-5 w-5 text-yellow-500" />
- <AlertTitle>
- User API Keys have been replaced by Workspace API Keys.
- </AlertTitle>
- <AlertDescription className="text-neutral-500">
- We recommend creating a new{" "}
+ <div className="flex items-start gap-3 rounded-lg border border-amber-200 bg-amber-50 px-4 py-2.5">
+ <TriangleWarning className="mt-0.5 size-4 shrink-0 text-amber-600" />
+ <p className="flex-1 text-sm text-amber-900">
+ User API Keys have been replaced by Workspace API Keys. We recommend
+ creating a new{" "}
<a
href="https://dub.co/docs/api-reference/tokens"
target="_blank"
- className="font-medium underline underline-offset-4 hover:text-black"
+ className="font-medium underline underline-offset-2 transition-colors hover:text-neutral-800"
>
Workspace API Key
</a>{" "}
@@ -43,22 +39,14 @@ export default function TokensPageClient() {
<a
href="https://dub.co/blog/workspace-api-keys"
target="_blank"
- className="font-medium underline underline-offset-4 hover:text-black"
+ className="font-medium underline underline-offset-2 transition-colors hover:text-neutral-800"
>
Read the announcement.
</a>
- </AlertDescription>
- </Alert>
+ </p>
+ </div>
- <div className="rounded-lg border border-neutral-200 bg-white">
- <div className="flex flex-col space-y-3 p-5 sm:p-10">
- <h2 className="text-xl font-medium">Your API Keys</h2>
- <p className="text-sm text-neutral-500">
- These API keys allow other apps to access your account. Use it with
- caution – do not share your API key with others, or expose it in the
- browser or other client-side code
- </p>
- </div>
+ <div className="mt-6 rounded-lg border border-neutral-200 bg-white">
{isLoading || !tokens ? (
<div className="flex flex-col items-center justify-center space-y-4 pb-20 pt-10">
<LoadingSpinner className="h-6 w-6 text-neutral-500" />
diff --git a/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page.tsx b/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page.tsx
index 1ac838426c..f3935e4300 100644
--- a/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page.tsx
@@ -1,5 +1,20 @@
+import { PageContent } from "@/ui/layout/page-content";
+import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import TokensPageClient from "./page-client";
export default function TokensPage() {
- return <TokensPageClient />;
+ return (
+ <PageContent
+ title="API Keys"
+ titleInfo={{
+ title:
+ "These API keys allow other apps to access your account. Use it with caution – do not share your API key with others, or expose it in the browser or other client-side code",
+ href: "https://dub.co/docs/api-reference/tokens",
+ }}
+ >
+ <PageWidthWrapper>
+ <TokensPageClient />
+ </PageWidthWrapper>
+ </PageContent>
+ );
}
diff --git a/apps/web/lib/auth/partner.ts b/apps/web/lib/auth/partner.ts
index 6860351244..c61de781ee 100644
--- a/apps/web/lib/auth/partner.ts
+++ b/apps/web/lib/auth/partner.ts
@@ -68,7 +68,7 @@ export const withPartnerProfile = (
try {
const authorizationHeader = requestHeaders.get("Authorization");
if (authorizationHeader) {
- if (!authorizationHeader.includes("Bearer ")) {
+ if (!authorizationHeader.startsWith("Bearer ")) {
throw new DubApiError({
code: "bad_request",
message:
@@ -94,6 +94,7 @@ export const withPartnerProfile = (
hashedKey,
},
select: {
+ expires: true,
user: {
select: {
id: true,
diff --git a/apps/web/lib/auth/publishable-key.ts b/apps/web/lib/auth/publishable-key.ts
index 1693e11714..0317aec276 100644
--- a/apps/web/lib/auth/publishable-key.ts
+++ b/apps/web/lib/auth/publishable-key.ts
@@ -48,7 +48,7 @@ export const withPublishableKey = (
try {
const authorizationHeader = requestHeaders.get("Authorization");
if (authorizationHeader) {
- if (!authorizationHeader.includes("Bearer ")) {
+ if (!authorizationHeader.startsWith("Bearer ")) {
throw new DubApiError({
code: "bad_request",
message: "Invalid or missing publishable key.",
diff --git a/apps/web/lib/auth/session.ts b/apps/web/lib/auth/session.ts
index d8f881d852..1bc7cd71c0 100644
--- a/apps/web/lib/auth/session.ts
+++ b/apps/web/lib/auth/session.ts
@@ -37,7 +37,7 @@ export const withSession = (handler: WithSessionHandler) =>
const authorizationHeader = requestHeaders.get("Authorization");
if (authorizationHeader) {
- if (!authorizationHeader.includes("Bearer ")) {
+ if (!authorizationHeader.startsWith("Bearer ")) {
throw new DubApiError({
code: "bad_request",
message:
diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.ts
index 34f62c42d1..5e3894d15b 100644
--- a/apps/web/lib/auth/workspace.ts
+++ b/apps/web/lib/auth/workspace.ts
@@ -98,7 +98,7 @@ export const withWorkspace = (
try {
const authorizationHeader = requestHeaders.get("Authorization");
if (authorizationHeader) {
- if (!authorizationHeader.includes("Bearer ")) {
+ if (!authorizationHeader.startsWith("Bearer ")) {
throw new DubApiError({
code: "bad_request",
message:
@@ -183,10 +183,10 @@ export const withWorkspace = (
hashedKey,
},
select: {
+ expires: true,
...(isRestrictedToken && {
scopes: true,
projectId: true,
- expires: true,
installationId: true,
project: {
select: {
diff --git a/apps/web/tests/analytics/get-analytics-advanced.test.ts b/apps/web/tests/analytics/get-analytics-advanced.test.ts
index e4146c5dbe..791bbc3b3c 100644
--- a/apps/web/tests/analytics/get-analytics-advanced.test.ts
+++ b/apps/web/tests/analytics/get-analytics-advanced.test.ts
@@ -184,7 +184,7 @@ describe
});
test("multiple partnerIds filter (IS ONE OF)", async () => {
- const partnerIds = E2E_PARTNERS.map((p) => p.id).join(",");
+ const partnerIds = E2E_PARTNERS.map((p) => p.id);
const { status, data } = await http.get<any>({
path: `/analytics`,
query: {
@@ -192,7 +192,7 @@ describe
groupBy: "top_partners",
workspaceId,
interval: "all",
- partnerId: partnerIds,
+ partnerId: partnerIds.join(","),
},
});
@@ -202,7 +202,9 @@ describe
.safeParse(data);
expect(parsed.success).toBeTruthy();
expect(
- parsed.data?.every((item) => partnerIds.includes(item.partner.id)),
+ parsed.data?.every((item) =>
+ partnerIds.some((id) => id === item.partner.id),
+ ),
).toBe(true);
});
@@ -229,7 +231,7 @@ describe
});
test("exclude multiple partnerIds (IS NOT ONE OF)", async () => {
- const partnerIds = E2E_PARTNERS.map((p) => p.id).join(",");
+ const partnerIds = E2E_PARTNERS.map((p) => p.id);
const { status, data } = await http.get<any>({
path: `/analytics`,
query: {
@@ -237,7 +239,7 @@ describe
groupBy: "top_partners",
workspaceId,
interval: "all",
- partnerId: `-${partnerIds}`,
+ partnerId: `-${partnerIds.join(",")}`,
},
});
@@ -248,7 +250,7 @@ describe
expect(parsed.success).toBeTruthy();
expect(
parsed.data?.every(
- (item: any) => !partnerIds.includes(item.partner.id),
+ (item: any) => !partnerIds.some((id) => id === item.partner.id),
),
).toBe(true);
});