From a4cce7afed8813097dfc020aec16401ae0991ee3 Mon Sep 17 00:00:00 2001 From: k00b Date: Wed, 12 Feb 2025 10:10:25 -0600 Subject: [PATCH] only record landing of referree if they don't have referrer --- pages/api/auth/[...nextauth].js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pages/api/auth/[...nextauth].js b/pages/api/auth/[...nextauth].js index 7e3c466f..8f2d7ffa 100644 --- a/pages/api/auth/[...nextauth].js +++ b/pages/api/auth/[...nextauth].js @@ -105,12 +105,15 @@ function getCallbacks (req, res) { if (req.cookies.sn_referrer && user?.id) { const referrerData = await getReferrerData(req.cookies.sn_referrer, req.cookies.sn_referee_landing) if (referrerData?.referrerId && referrerData.referrerId !== parseInt(user?.id)) { - // if we have recorded a referee landing, record it in the db - if (referrerData.type && referrerData.typeId) { - await prisma.oneDayReferral.create({ data: { ...referrerData, refereeId: user.id, landing: true } }) - } + // if user doesn't have a referrer, record it in the db const { count } = await prisma.user.updateMany({ where: { id: user.id, referrerId: null }, data: { referrerId: referrerData.referrerId } }) - if (count > 0) notifyReferral(referrerData.referrerId) + if (count > 0) { + // if user has an associated landing, record it in the db + if (referrerData.type && referrerData.typeId) { + await prisma.oneDayReferral.create({ data: { ...referrerData, refereeId: user.id, landing: true } }) + } + notifyReferral(referrerData.referrerId) + } } } }