The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
remove unused
Kiran Kcfeb831d0aed
diff --git a/apps/web/lib/auth/api.ts b/apps/web/lib/auth/api.tsdeleted file mode 100644index 08a68dd01c..0000000000--- a/apps/web/lib/auth/api.ts+++ /dev/null@@ -1,89 +0,0 @@-import { prisma } from "@/lib/prisma";-import { getSearchParams } from "@dub/utils";-import { DubApiError, handleAndReturnErrorResponse } from "../api/errors";-import { ratelimit } from "../upstash";-import { hashToken } from "./hash-token";--interface withApiAuthHandler {- ({- req,- params,- searchParams,- headers,- }: {- req: Request;- params: Record<string, string>;- searchParams: Record<string, string>;- headers?: Record<string, string>;- }): Promise<Response>;-}--export const withApiAuth = (handler: withApiAuthHandler, {}: {} = {}) => {- return async (- req: Request,- { params }: { params: Record<string, string> | undefined },- ) => {- const searchParams = getSearchParams(req.url);-- let headers = {};-- try {- const authorizationHeader = req.headers.get("Authorization");- if (authorizationHeader) {- if (!authorizationHeader.includes("Bearer ")) {- throw new DubApiError({- code: "bad_request",- message:- "Misconfigured authorization header. Did you forget to add 'Bearer '? Learn more: https://d.to/auth",- });- }- const apiKey = authorizationHeader.replace("Bearer ", "");-- const hashedKey = await hashToken(apiKey);-- const token = await prisma.token.findUnique({- where: {- hashedKey,- },- });- if (!token) {- throw new DubApiError({- code: "unauthorized",- message: "Unauthorized: Invalid API key.",- });- }-- const { success, limit, reset, remaining } = await ratelimit(- 600,- "1 m",- ).limit(apiKey);-- headers = {- "Retry-After": reset.toString(),- "X-RateLimit-Limit": limit.toString(),- "X-RateLimit-Remaining": remaining.toString(),- "X-RateLimit-Reset": reset.toString(),- };-- if (!success) {- throw new DubApiError({- code: "rate_limit_exceeded",- message: "Too many requests.",- });- }-- // record usage for analytics- // record last used-- return await handler({- req,- params: params || {},- searchParams,- headers,- });- }- } catch (error) {- return handleAndReturnErrorResponse(error, headers);- }- };-};diff --git a/apps/web/lib/auth/workspace-edge.ts b/apps/web/lib/auth/workspace-edge.tsindex b364078d55..65f3649805 100644--- a/apps/web/lib/auth/workspace-edge.ts+++ b/apps/web/lib/auth/workspace-edge.ts@@ -55,16 +55,12 @@ export const withWorkspaceEdge = ("enterprise",], // if the action needs a specific planrequiredAddOn,- needNotExceededClicks, // if the action needs the user to not have exceeded their clicks usage- needNotExceededLinks, // if the action needs the user to not have exceeded their links usageneedNotExceededAI, // if the action needs the user to not have exceeded their AI usagefeatureFlag, // if the action needs a specific feature flagrequiredPermissions = [],}: {requiredPlan?: Array<PlanProps>;requiredAddOn?: AddOns;- needNotExceededClicks?: boolean;- needNotExceededLinks?: boolean;needNotExceededAI?: boolean;featureFlag?: BetaFeatures;requiredPermissions?: PermissionAction[];@@ -335,34 +331,6 @@ export const withWorkspaceEdge = (}}- // clicks usage overage checks- if (needNotExceededClicks && workspace.usage > workspace.usageLimit) {- throw new DubApiError({- code: "forbidden",- message: exceededLimitError({- plan: workspace.plan,- limit: workspace.usageLimit,- type: "clicks",- }),- });- }-- // links usage overage checks- if (- needNotExceededLinks &&- workspace.linksUsage > workspace.linksLimit &&- (workspace.plan === "free" || workspace.plan === "pro")- ) {- throw new DubApiError({- code: "forbidden",- message: exceededLimitError({- plan: workspace.plan,- limit: workspace.linksLimit,- type: "links",- }),- });- }-// AI usage overage checksif (needNotExceededAI && workspace.aiUsage > workspace.aiLimit) {throw new DubApiError({