Scheduling infrastructure for absolutely everyone.
Update `dclid` → `dub_id` (#16670)
Steven Tey4cbf9ec9ab8e
diff --git a/apps/web/lib/settings/license-key/new/getServerSideProps.tsx b/apps/web/lib/settings/license-key/new/getServerSideProps.tsxindex 8b8be211d17..52d9361a5da 100644--- a/apps/web/lib/settings/license-key/new/getServerSideProps.tsx+++ b/apps/web/lib/settings/license-key/new/getServerSideProps.tsx@@ -7,7 +7,9 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>const session = await getServerSession({req: context.req,res: context.res,- authOptions: getOptions({ getDclid: () => context.req.cookies.dclid }),+ authOptions: getOptions({+ getDubId: () => context.req.cookies.dub_id || context.req.cookies.dclid,+ }),});// Disable this check if we ever make this self serve.if (session?.user.role !== "ADMIN") {diff --git a/apps/web/pages/api/auth/[...nextauth].tsx b/apps/web/pages/api/auth/[...nextauth].tsxindex ccb457fad96..b797e30f6cb 100644--- a/apps/web/pages/api/auth/[...nextauth].tsx+++ b/apps/web/pages/api/auth/[...nextauth].tsx@@ -5,6 +5,6 @@ import { getOptions } from "@calcom/features/auth/lib/next-auth-options";// pass req to NextAuth: https://github.com/nextauthjs/next-auth/discussions/469const handler = (req: NextApiRequest, res: NextApiResponse) =>- NextAuth(req, res, getOptions({ getDclid: () => req.cookies.dclid }));+ NextAuth(req, res, getOptions({ getDubId: () => req.cookies.dub_id || req.cookies.dclid }));export default handler;diff --git a/packages/features/auth/lib/get-server-session-for-app-dir.ts b/packages/features/auth/lib/get-server-session-for-app-dir.tsindex 37d83b87b74..6c5b9a04e83 100644--- a/packages/features/auth/lib/get-server-session-for-app-dir.ts+++ b/packages/features/auth/lib/get-server-session-for-app-dir.ts@@ -4,5 +4,9 @@ import { cookies } from "next/headers";import { getOptions } from "./next-auth-options";export async function getServerSessionForAppDir() {- return await getServerSession(getOptions({ getDclid: () => cookies().get("dclid")?.value }));+ return await getServerSession(+ getOptions({+ getDubId: () => cookies().get("dub_id")?.value || cookies().get("dclid")?.value,+ })+ );}diff --git a/packages/features/auth/lib/next-auth-options.ts b/packages/features/auth/lib/next-auth-options.tsindex b75a98a13c4..d175b8e4baf 100644--- a/packages/features/auth/lib/next-auth-options.ts+++ b/packages/features/auth/lib/next-auth-options.ts@@ -408,10 +408,10 @@ const mapIdentityProvider = (providerName: string) => {};export const getOptions = ({- getDclid,+ getDubId,}: {/** so we can extract the Dub cookie in both pages and app routers */- getDclid: () => string | undefined;+ getDubId: () => string | undefined;}): AuthOptions => ({// eslint-disable-next-line @typescript-eslint/ban-ts-comment// @ts-ignore@@ -948,15 +948,15 @@ export const getOptions = ({// we should use NextAuth's isNewUser flag instead: https://next-auth.js.org/configuration/events#signinconst isNewUser = new Date(user.createdAt) > new Date(Date.now() - 10 * 60 * 1000);if ((isENVDev || IS_CALCOM) && process.env.DUB_API_KEY && isNewUser) {- const dclid = getDclid();- // check if there's a dclid cookie set by @dub/analytics- if (dclid) {+ const clickId = getDubId();+ // check if there's a clickId (dub_id) cookie set by @dub/analytics+ if (clickId) {// here we use waitUntil – meaning this code will run async to not block the main threadwaitUntil(// if so, send a lead event to Dub// @see https://d.to/conversions/next-authdub.track.lead({- clickId: dclid,+ clickId,eventName: "Sign Up",customerId: user.id.toString(),customerName: user.name,