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.

If an active public token is present for a link, return it instead of creating a new one

Kiran Keadb8fcb3499
diff --git a/apps/web/lib/referrals/create-referral-token.ts b/apps/web/lib/referrals/create-referral-token.ts
index 0a5e66d5bd..9d5563f396 100644
--- a/apps/web/lib/referrals/create-referral-token.ts
+++ b/apps/web/lib/referrals/create-referral-token.ts
@@ -27,6 +27,16 @@ export const createReferralPublicToken = async ({
});
}
+ const token = await prisma.embedPublicToken.findFirst({
+ where: {
+ linkId,
+ },
+ });
+
+ if (token) {
+ return token;
+ }
+
return await prisma.embedPublicToken.create({
data: {
linkId,
diff --git a/apps/web/prisma/schema/token.prisma b/apps/web/prisma/schema/token.prisma
index 3f19527e5c..5bb63bc5a9 100644
--- a/apps/web/prisma/schema/token.prisma
+++ b/apps/web/prisma/schema/token.prisma
@@ -68,7 +68,7 @@ model PasswordResetToken {
model EmbedPublicToken {
id String @id @default(cuid())
- linkId String
+ linkId String // TODO: Do we wanna make this unique? One token per link at a time?
publicToken String @unique
expires DateTime
createdAt DateTime @default(now())