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.

withEmbedToken

Steven Teya6d297e4d552
diff --git a/apps/web/app/api/analytics/client/route.ts b/apps/web/app/api/analytics/client/route.ts
index 59f01701ff..ba9983b50c 100644
--- a/apps/web/app/api/analytics/client/route.ts
+++ b/apps/web/app/api/analytics/client/route.ts
@@ -1,11 +1,11 @@
import { getAnalytics } from "@/lib/analytics/get-analytics";
import { calculateEarnings } from "@/lib/api/sales/commission";
-import { withAuth } from "@/lib/referrals/auth";
+import { withEmbedToken } from "@/lib/referrals/auth";
import { analyticsQuerySchema } from "@/lib/zod/schemas/analytics";
import { NextResponse } from "next/server";
// GET /api/analytics/client - get analytics for the current link
-export const GET = withAuth(async ({ link, searchParams, program }) => {
+export const GET = withEmbedToken(async ({ link, searchParams, program }) => {
const parsedParams = analyticsQuerySchema
.pick({
event: true,
diff --git a/apps/web/app/api/events/client/route.ts b/apps/web/app/api/events/client/route.ts
index 464108c44d..582e6de0ff 100644
--- a/apps/web/app/api/events/client/route.ts
+++ b/apps/web/app/api/events/client/route.ts
@@ -1,11 +1,11 @@
import { getEvents } from "@/lib/analytics/get-events";
import { calculateEarnings } from "@/lib/api/sales/commission";
-import { withAuth } from "@/lib/referrals/auth";
+import { withEmbedToken } from "@/lib/referrals/auth";
import { eventsQuerySchema } from "@/lib/zod/schemas/analytics";
import { NextResponse } from "next/server";
// GET /api/events/client - get events for the current link
-export const GET = withAuth(async ({ searchParams, program, link }) => {
+export const GET = withEmbedToken(async ({ searchParams, program, link }) => {
const parsedParams = eventsQuerySchema
.omit({
linkId: true,
diff --git a/apps/web/app/api/referrals/invite/route.ts b/apps/web/app/api/referrals/invite/route.ts
index 3f9a160bab..01f7d24384 100644
--- a/apps/web/app/api/referrals/invite/route.ts
+++ b/apps/web/app/api/referrals/invite/route.ts
@@ -2,11 +2,11 @@ import { invitePartner } from "@/lib/api/partners/invite-partner";
import { parseRequestBody } from "@/lib/api/utils";
import { requestPartnerInviteSchema } from "@/lib/dots/schemas";
import { prisma } from "@/lib/prisma";
-import { withAuth } from "@/lib/referrals/auth";
+import { withEmbedToken } from "@/lib/referrals/auth";
import { NextResponse } from "next/server";
// GET /api/referrals/invite - check if a partner is already invited to a program
-export const GET = withAuth(async ({ link, program }) => {
+export const GET = withEmbedToken(async ({ link, program }) => {
const [programEnrollment, programInvite] = await Promise.all([
prisma.programEnrollment.findFirst({
where: {
@@ -30,17 +30,19 @@ export const GET = withAuth(async ({ link, program }) => {
});
// POST /api/referrals/invite - invite a partner to dub partners
-export const POST = withAuth(async ({ req, link, program, workspace }) => {
- const { email } = requestPartnerInviteSchema.parse(
- await parseRequestBody(req),
- );
+export const POST = withEmbedToken(
+ async ({ req, link, program, workspace }) => {
+ const { email } = requestPartnerInviteSchema.parse(
+ await parseRequestBody(req),
+ );
- const programInvited = await invitePartner({
- email,
- program,
- link,
- workspace,
- });
+ const programInvited = await invitePartner({
+ email,
+ program,
+ link,
+ workspace,
+ });
- return NextResponse.json(programInvited);
-});
+ return NextResponse.json(programInvited);
+ },
+);
diff --git a/apps/web/app/api/referrals/link/route.ts b/apps/web/app/api/referrals/link/route.ts
index dd132f5ceb..cde10416cf 100644
--- a/apps/web/app/api/referrals/link/route.ts
+++ b/apps/web/app/api/referrals/link/route.ts
@@ -1,8 +1,8 @@
-import { withAuth } from "@/lib/referrals/auth";
+import { withEmbedToken } from "@/lib/referrals/auth";
import { NextResponse } from "next/server";
// GET /api/referrals/link - get the link for the given affiliate
-export const GET = withAuth(async ({ link }) => {
+export const GET = withEmbedToken(async ({ link }) => {
const { id, url, shortLink, clicks, leads, sales, saleAmount } = link;
return NextResponse.json({
diff --git a/apps/web/app/api/referrals/program/route.ts b/apps/web/app/api/referrals/program/route.ts
index 57a9237732..9d73d2c060 100644
--- a/apps/web/app/api/referrals/program/route.ts
+++ b/apps/web/app/api/referrals/program/route.ts
@@ -1,8 +1,8 @@
-import { withAuth } from "@/lib/referrals/auth";
+import { withEmbedToken } from "@/lib/referrals/auth";
import { ProgramSchema } from "@/lib/zod/schemas/programs";
import { NextResponse } from "next/server";
// GET /api/referrals/program - get the program for the given affiliate
-export const GET = withAuth(async ({ program }) => {
+export const GET = withEmbedToken(async ({ program }) => {
return NextResponse.json(ProgramSchema.parse(program));
});
diff --git a/apps/web/app/api/referrals/sales/count/route.ts b/apps/web/app/api/referrals/sales/count/route.ts
index e212938170..d863ce6c45 100644
--- a/apps/web/app/api/referrals/sales/count/route.ts
+++ b/apps/web/app/api/referrals/sales/count/route.ts
@@ -1,11 +1,11 @@
import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";
import { prisma } from "@/lib/prisma";
-import { withAuth } from "@/lib/referrals/auth";
+import { withEmbedToken } from "@/lib/referrals/auth";
import { getPartnerSalesCountQuerySchema } from "@/lib/zod/schemas/partners";
import { NextResponse } from "next/server";
// GET /api/referrals/sales/count – get sales count for a link
-export const GET = withAuth(async ({ searchParams, link }) => {
+export const GET = withEmbedToken(async ({ searchParams, link }) => {
const parsed = getPartnerSalesCountQuerySchema.parse(searchParams);
const { startDate, endDate } = getStartEndDates(parsed);
diff --git a/apps/web/app/api/referrals/sales/route.ts b/apps/web/app/api/referrals/sales/route.ts
index 70f7cd954b..5737b8bc9b 100644
--- a/apps/web/app/api/referrals/sales/route.ts
+++ b/apps/web/app/api/referrals/sales/route.ts
@@ -1,11 +1,11 @@
import { prisma } from "@/lib/prisma";
-import { withAuth } from "@/lib/referrals/auth";
+import { withEmbedToken } from "@/lib/referrals/auth";
import z from "@/lib/zod";
import { PartnerSaleResponseSchema } from "@/lib/zod/schemas/partners";
import { NextResponse } from "next/server";
// GET /api/referrals/sales – get sales for a link
-export const GET = withAuth(async ({ link }) => {
+export const GET = withEmbedToken(async ({ link }) => {
const sales = await prisma.sale.findMany({
where: {
linkId: link.id,
diff --git a/apps/web/lib/referrals/auth.ts b/apps/web/lib/referrals/auth.ts
index c506ed2e2d..0228f6b57e 100644
--- a/apps/web/lib/referrals/auth.ts
+++ b/apps/web/lib/referrals/auth.ts
@@ -7,7 +7,7 @@ import { AxiomRequest, withAxiom } from "next-axiom";
import { cookies } from "next/headers";
import { EMBED_PUBLIC_TOKEN_COOKIE_NAME } from "./constants";
-interface WithAuthHandler {
+interface WithEmbedTokenHandler {
({
req,
params,
@@ -25,7 +25,7 @@ interface WithAuthHandler {
}): Promise<Response>;
}
-export const withAuth = (handler: WithAuthHandler) => {
+export const withEmbedToken = (handler: WithEmbedTokenHandler) => {
return withAxiom(
async (
req: AxiomRequest,