The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update params + headers for withAdmin and withSession helpers
Steven Tey8a848cac8232
diff --git a/apps/web/lib/auth/admin.ts b/apps/web/lib/auth/admin.tsindex d50b096eb1..011a6f189a 100644--- a/apps/web/lib/auth/admin.ts+++ b/apps/web/lib/auth/admin.ts@@ -34,8 +34,9 @@ export const withAdmin =(handler: WithAdminHandler) =>async (req: Request,- { params = {} }: { params: Record<string, string> | undefined },+ { params: initialParams }: { params: Promise<Record<string, string>> },) => {+ const params = (await initialParams) || {};const session = await getSession();if (!session?.user) {return new Response("Unauthorized: Login required.", { status: 401 });diff --git a/apps/web/lib/auth/session.ts b/apps/web/lib/auth/session.tsindex cb784594f4..4f7aad3a90 100644--- a/apps/web/lib/auth/session.ts+++ b/apps/web/lib/auth/session.ts@@ -4,6 +4,7 @@ import { prisma } from "@dub/prisma";import { getSearchParams } from "@dub/utils";import { waitUntil } from "@vercel/functions";import { AxiomRequest, withAxiom } from "next-axiom";+import { headers } from "next/headers";import { hashToken } from "./hash-token";import { Session, getSession } from "./utils";@@ -25,13 +26,15 @@ export const withSession = (handler: WithSessionHandler) =>withAxiom(async (req: AxiomRequest,- { params = {} }: { params: Record<string, string> | undefined },+ { params: initialParams }: { params: Promise<Record<string, string>> },) => {+ const params = (await initialParams) || {};+ let headersList = await headers();+try {let session: Session | undefined;- let headers = {};- const authorizationHeader = req.headers.get("Authorization");+ const authorizationHeader = headersList.get("Authorization");if (authorizationHeader) {if (!authorizationHeader.includes("Bearer ")) {throw new DubApiError({@@ -71,17 +74,15 @@ export const withSession = (handler: WithSessionHandler) =>"1 m",).limit(apiKey);- headers = {- "Retry-After": reset.toString(),- "X-RateLimit-Limit": limit.toString(),- "X-RateLimit-Remaining": remaining.toString(),- "X-RateLimit-Reset": reset.toString(),- };+ headersList.set("Retry-After", reset.toString());+ headersList.set("X-RateLimit-Limit", limit.toString());+ headersList.set("X-RateLimit-Remaining", remaining.toString());+ headersList.set("X-RateLimit-Reset", reset.toString());if (!success) {return new Response("Too many requests.", {status: 429,- headers,+ headers: headersList,});}waitUntil(