fix: new user detection for dub analytics (#16695)

This commit is contained in:
Omar López
2024-09-17 19:19:25 -07:00
committed by GitHub
parent 5ad73607f0
commit 3a5325f2a8
@@ -237,7 +237,7 @@ const providers: Provider[] = [
belongsToActiveTeam: hasActiveTeams,
locale: user.locale,
profile: user.allProfiles[0],
createdAt: user.createdDate,
createdDate: user.createdDate,
};
},
}),
@@ -941,12 +941,12 @@ export const getOptions = ({
*/
const user = message.user as User & {
username: string;
createdAt: string;
createdDate: string;
};
// check if the user was created in the last 10 minutes
// this is a workaround  in the future once we move to use the Account model in the DB
// we should use NextAuth's isNewUser flag instead: https://next-auth.js.org/configuration/events#signin
const isNewUser = new Date(user.createdAt) > new Date(Date.now() - 10 * 60 * 1000);
const isNewUser = new Date(user.createdDate) > new Date(Date.now() - 10 * 60 * 1000);
if ((isENVDev || IS_CALCOM) && process.env.DUB_API_KEY && isNewUser) {
const clickId = getDubId();
// check if there's a clickId (dub_id) cookie set by @dub/analytics