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.

Throw error for missing auth header

Steven Tey78e1aa538449
diff --git a/apps/web/lib/auth/workspace-edge.ts b/apps/web/lib/auth/workspace-edge.ts
index c665e1c810..49bef17ed7 100644
--- a/apps/web/lib/auth/workspace-edge.ts
+++ b/apps/web/lib/auth/workspace-edge.ts
@@ -105,11 +105,18 @@ export const withWorkspaceEdge = (
// if there's no workspace ID or slug and it's not a restricted token
// For restricted tokens, we find the workspaceId from the token
if (!idOrSlug && !isRestrictedToken) {
- throw new DubApiError({
- code: "not_found",
- message:
- "Workspace ID not found. Did you forget to include a `workspaceId` query parameter? It looks like you might be using personal API keys, we also recommend refactoring to workspace API keys: https://d.to/keys",
- });
+ if (!authorizationHeader) {
+ throw new DubApiError({
+ code: "unauthorized",
+ message: "Missing Authorization header.",
+ });
+ } else {
+ throw new DubApiError({
+ code: "not_found",
+ message:
+ "Workspace ID not found. Did you forget to include a `workspaceId` query parameter? It looks like you might be using personal API keys, we also recommend refactoring to workspace API keys: https://d.to/keys",
+ });
+ }
}
if (idOrSlug) {
diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.ts
index 4b7cf97992..3eb4723f12 100644
--- a/apps/web/lib/auth/workspace.ts
+++ b/apps/web/lib/auth/workspace.ts
@@ -115,11 +115,18 @@ export const withWorkspace = (
headers,
});
} else {
- throw new DubApiError({
- code: "not_found",
- message:
- "Workspace ID not found. Did you forget to include a `workspaceId` query parameter? It looks like you might be using personal API keys, we also recommend refactoring to workspace API keys: https://d.to/keys",
- });
+ if (!authorizationHeader) {
+ throw new DubApiError({
+ code: "unauthorized",
+ message: "Missing Authorization header.",
+ });
+ } else {
+ throw new DubApiError({
+ code: "not_found",
+ message:
+ "Workspace ID not found. Did you forget to include a `workspaceId` query parameter? It looks like you might be using personal API keys, we also recommend refactoring to workspace API keys: https://d.to/keys",
+ });
+ }
}
}