The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
use unique index for partner-profile
Steven Tey7de010a7e952
diff --git a/apps/web/lib/auth/partner.ts b/apps/web/lib/auth/partner.tsindex b8d5f0f47b..bf6c3ef99b 100644--- a/apps/web/lib/auth/partner.ts+++ b/apps/web/lib/auth/partner.ts@@ -45,32 +45,27 @@ export const withPartnerProfile = (const searchParams = getSearchParams(req.url);const { defaultPartnerId, id: userId } = session.user;- const partner = await prisma.partner.findFirst({+ if (!defaultPartnerId) {+ throw new DubApiError({+ code: "not_found",+ message: "Partner profile not found.",+ });+ }++ const partnerUser = await prisma.partnerUser.findUnique({where: {- ...(defaultPartnerId && {- id: defaultPartnerId,- }),- users: {- some: {- userId,- },+ userId_partnerId: {+ userId,+ partnerId: defaultPartnerId,},},include: {- users: true,+ partner: true,},});- // partner profile doesn't exist- if (!partner || !partner.users) {- throw new DubApiError({- code: "not_found",- message: "Partner profile not found.",- });- }-- // partner profile exists but user is not part of it- if (partner.users.length === 0) {+ // partnerUser relationship doesn't exist+ if (!partnerUser) {throw new DubApiError({code: "not_found",message: "Partner profile not found.",@@ -82,7 +77,7 @@ export const withPartnerProfile = (params,searchParams,session,- partner,+ partner: partnerUser.partner,});} catch (error) {req.log.error(error);diff --git a/apps/web/lib/swr/use-partner-profile.ts b/apps/web/lib/swr/use-partner-profile.tsindex 10e691f006..b4b6c6442f 100644--- a/apps/web/lib/swr/use-partner-profile.ts+++ b/apps/web/lib/swr/use-partner-profile.ts@@ -20,7 +20,7 @@ export default function usePartnerProfile() {isLoading,mutate,} = useSWR<PartnerProps>(- isPartnerPage && partnerId && `/api/partner-profile`,+ isPartnerPage && partnerId && "/api/partner-profile",fetcher,{dedupingInterval: 60000,